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

why did while true do crash my game?

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

4 comments

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 ?

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.

0

ok I will try

0

It worked thanks

1 answer

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

1 comment

0

ok

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