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

Why doesn't this faster walkspeed script run properly?

while true do
	local sped = script.val.Value
	
	if sped > 0 then
		sped = sped - 1
		script.Parent.Humanoid.WalkSpeed = 25
		wait(1)
		script.Parent.Humanoid.WalkSpeed = 16
	end
end

This is a script in StarterCharacterScripts that is supposed to make you run faster when you have more speed in the speed value. You are supposed to step on these purple circles that makes you run faster for 3 seconds, and it does that by setting the value inside the script to 3, and then the script makes you run for as long as the value is set (in seconds). It doesn't run though, and the error is Script timeout: exhausted allowed execution time. I don't know if its a problem with the script or what the error is. None of my other scripts do this, so it has nothing to do with the loop (i think). If you could help, I would appreciate that. Thanks.

1 answer

Add a wait() outside the if statement

while true do
    local sped = script.val.Value

    if sped > 0 then
        sped = sped - 1
        script.Parent.Humanoid.WalkSpeed = 25
        wait(1)
        script.Parent.Humanoid.WalkSpeed = 16
    end

    wait()
end

2 comments

0

You can also do while wait() do at line 1

0

Is there a major difference between while wait() do & while true do? It seems like they both hold the same purpose.

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