Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script keeps running after I stop holding Shift?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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 
0
It worked, thanks! TheNINJA152 85 — 4y
Ad

Answer this question