I have a script where the player's speed goes up by 1 every 2 seconds until it reaches 25
My problem is, It keeps on going after 25 and until I stop holding shift
local p = game.Players.LocalPlayer
local char = p.Character
if not p.Character then
repeat wait() until p.Character
end
local human = char.Humanoid
local anim = game.Workspace:WaitForChild("Animation")
local loadAnim = human:LoadAnimation(anim)
local UIS = game:GetService("UserInputService")
local holdingShiftKey = false
UIS.InputBegan:Connect(function(inputObject)
if(inputObject.KeyCode==Enum.KeyCode.LeftShift)then
holdingShiftKey = true
while holdingShiftKey do
loadAnim:Play()
repeat wait(2)
char.Humanoid.WalkSpeed += 1
until char.Humanoid.WalkSpeed == 25 or not holdingShiftKey
end
end
end)
UIS.InputEnded:Connect(function(inputObject)
if(inputObject.KeyCode==Enum.KeyCode.LeftShift)then
holdingShiftKey = false
char.Humanoid.WalkSpeed = 16
loadAnim:Stop()
end
end)
Can anyone help me?

1 comment
Thanks for explaining this to me, I managed to fix it after seeing your answer