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

Is there a way to yield the thread until something happens?

Is there any way to yield the current thread until something happens?

For example,

game.Workspace:WaitForChild("Part")

will yield the thread until a child named 'Part' is added. Is there any other way to yield the thread?

1 comment

0

Anyone?

2 answers

You could do something like

while true do
	newPart=Workspace.ChildAdded:Wait()
	if newPart.Name=="Part" then
		break
	end
end

Hope this helps.

Yes, there is. You can use "repeat". For example:

repeat
--whatever code you want to repeat
until
x.Value == 30 --change this to whatever you want it to repeat until

I hope that answers your question! If so, please upvote and accept this answer.

1 comment

0

This code will crash the game, as there is no wait() in the body of the repeat. As well, this is a laggy, busywait. Use Defaultio's method instead.

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