I want to make it so that the player gets faster the longer they press the keys but it doesnt seem to be working. Ive only just started scripting so I might not understand your solution...
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local tweenS = game:GetService("TweenService")
local maxSpeed = 30
local initialSpeed = 16
local player = players.LocalPlayer
local WKey = Enum.KeyCode.W
local SKey = Enum.KeyCode.S
local AKey = Enum.KeyCode.A
local DKey = Enum.KeyCode.D
local keyboard = Enum.UserInputType.Keyboard
local humanoid = player.Character.Humanoid
local tween1 = tweenS:Create(humanoid, TweenInfo.new(5), {WalkSpeed = maxSpeed})
local tween2 = tweenS:Create(humanoid, TweenInfo.new(5), {WalkSpeed = initialSpeed})
local function beginWalk(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == keyboard then
local keycode = input.KeyCode
if keycode == WKey or keycode == SKey or AKey or keycode == DKey then
tween2:Cancel()
tween1:Play()
end
end
end
end
local function endWalk(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == keyboard then
local keycode = input.KeyCode
if keycode == WKey or keycode == SKey or AKey or keycode == DKey then
tween1:Cancel()
tween2:Play()
end
end
end
end
userInput.InputBegan:Connect(beginWalk)
userInput.InputEnded:Connect(endWalk)
** You are now Level 5! **