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

why did while true do crash my game?

Asked by 6 years ago
orders = {"I wanna have a bloxycola plz","I wanna have doritos","I wanna have a bowling shoes plz"}

while true do
    if script.Parent.YesNo.Value == false then
        script.Parent.YesNo.Value = true
        human = game.Lighting.People:GetChildren()
        humanclone = math.random(1, #human)
        humanclone = human[humanclone]
        h = math.random(1, #orders)
        humanclone.Say.Value = orders[h]
        clonehuman = humanclone:Clone()
        clonehuman.Parent = game.Workspace
        clonehuman:MoveTo(script.Parent.Position)
        wait(5)
    end
    end

I am having a problem with it, It should do loop but when it start it should stop generating characters but the problem is when I active it, it start to crash and spawn the character but no more code was loaded can somebody look at it? note it says warning in line 2 but I dont notice the error

0
If you want it to stop generating the characters, use break . I'm not sure why it's lagging too, maybe add wait(5) below while true do ? liteImpulse 47 — 6y
0
You might have to place the wait directly behind the 'while true do'. This is so the loop doesn't start before necessary components of the script load. obcdino 113 — 6y
0
ok I will try HillsMaster 34 — 6y
0
It worked thanks HillsMaster 34 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

Place the wait() directly inside the while loop. Currently the script only waits while script.Parent.YesNo.Value is false; while the value is true, it is trying to go through the loop infinite times per second.

while true do
    if value == false then
        wait()
    end
end

should be:

while true do
    if value == false then

    end
    wait()
end
0
ok HillsMaster 34 — 6y
Ad

Answer this question