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

Game script timeout Error - While true do - How to fix?

Asked by 4 years ago

I am trying to make my script repeat so I am using While true do however whenever I use it it does Game script timeout. I think I need wait somewhere but I've put it everywhere I can think of. Here's the code:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
            while true do

                if player.leaderstats.speed.Value <= 16 then
                    humanoid.WalkSpeed = 16 
                else
                    humanoid.WalkSpeed = 0.1 * player.leaderstats.speed.Value
                wait(1)
            end
        end
    end)
end)

0
try replacing true with wait() p0vd 207 — 4y
0
I have no idea how that did it but thanks! Everbyte 6 — 4y

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

Your wait(1) function is inside the else statement, meaning that if the original condition is met(player.leaderstats.speed.Value <= 16) then the program won't wait.

fix:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
            while true do

                if player.leaderstats.speed.Value <= 16 then
                    humanoid.WalkSpeed = 16
wait(1) 
                else
                    humanoid.WalkSpeed = 0.1 * player.leaderstats.speed.Value
                wait(1)
            end
        end
    end)
end)

0
Thanks, I understand now Everbyte 6 — 4y
0
np Robowon1 323 — 4y
Ad

Answer this question