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

Why does this loop only works twice?

	while true do
		wait()
		if v.Value ~= 1 then
			print("bye")
	repeat wait() until v.Value == 1
end
end

At the beginning, it was working once. Now, this loop works for 2 times and then it stops responding to anything. In studio, it works normally. The script is a LocalScript.

1 answer

✓ Accepted answer

###Well, you shouldn't be using a loop to check if a property has changed. This is why the Changed event exists, to check if a property changes. The good thing is that the Changed event fires only when a property changes, so no code is running every 0.0299 seconds or however long the default wait time is.

v.Changed:Connect(function()
    wait() 

    if v.Value ~= 1 then
        print("bye")
     end
end)

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