Infinite printing bug

hello im trying to see if a value goes to empty to something but the problem is that when its going to true, my roblox studio freezes and " Script timeout: exhausted allowed execution time". I put a condition that stopped it but it still prints it.



	while true do
	if script.Parent.isInMatch.Value == false then 
		wait(0.25)
		print("Test")
		if script.Parent.PlayerOne.Value ~= "" then
			script.Parent.isInMatch.Value = true
			print("On")
		end
	end
end
	

2 Likes

Try moving the wait(0.25) to the line directly after while true do

Alternatively, add wait() in between the 2nd and 3rd end

i put it after the condition to not cause lag. since there is gonna be like 9 times this code running at the same time. It wont cause lag right? If so, how can i remove it

The best way to get rid of that loop is when your condition is met use ‘break’

and if i do use break, can it run again later?

or i can just disable the script right?

It is better to use Runservice for situations like this, as while true loops aren’t as good

for example

local runservice = game:GetService("RunService")

local In_match = script.Parent:WaitForChild("isInMatch")

runservice.Heartbeat:Connect(function()
	if In_match.Value == false then
		task.wait(.25)
		print("Test")
		
		if script.Parent.PlayerOne.Value ~= "" then
			In_match.Value = true
			print('On')
		end
	end
end)

1 Like

Thanks you, it works fine now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.