Issue with running script when disabling running while running

In my game, a player can perfectly begin running and stop running by pausing in between switches, although if you are currently running and click ctrl it does infact slow the players speed down, but does not stop the animation of the running.

On line 89 is where I made it so that it would stop if the player did infact click the ctrl button while running, which it does slow down the speed as the function tells it to do, but it doesn’t stop the animation of the running.

Most likely do to the while loop in your script. When you stop the run animation the loop is still looping for one more time it notices the run animation isn’t playing and then plays it again

If you want to test if this is true just put a print after line 81.

To stop this you can either add a wait after disabling togglerun

local function stopRun()
toggleRun = false
delAttr("Moving")
task.Wait(0.05)
runAnim:Stop()
hum.WalkSpeed = 16
end

Or you can add in if statement to the line 81 which plays the animation

if toggleRun == true then
runAnim:Play()
end

Sorry for the late reply man, been busy with some stuff. The task.wait worked perfectly fine btw! thanks for the pointer! ill be sure to remember this whenever im doing something like this again :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.