Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script keeps running after I stop holding Shift?

I'm trying to make a running script where every 2 seconds of you holding Shift your WalkSpeed goes up by 1 until it reaches 25

After I stop holding shift the animation ends but it keeps going up until 25 even though I'm not 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 = char.Humanoid.WalkSpeed + 1
				until char.Humanoid.WalkSpeed == 25
        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)

Does anyone have a fix for this?

1 answer

✓ Accepted answer

u never added anything to stop the repeat until , so it keeps on doing that until it reaches the exit condition

repeat
	wait(2)
	char.Humanoid.WalkSpeed += 1
until char.Humanoid.WalkSpeed == 25 or not holdingShiftKey 

1 comment

0

It worked, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.