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

is there a way to check for an infinite yield?

I'm trying to run a check on whether something exists or not and to solve the problem automatically in case of random glitches. I usually do this by checking whether a value is nil or not, but since it comes out as an infinite yield, I need a new way to check if the yield is infinite. what is the alternative for | if == nil then | to check if for an infinite yield instead

here's the code btw

if game.ServerStorage.maps:WaitForChild("friendship_park") == nil then
		if game.ServerStorage:FindFirstChild("friendship_park") == nil then
			local map_1 = game.Workspace.friendship_park
			map_1.Parent = game.serverstorage.maps
		else
			local map_1 = game.Workspace.MapHolder.friendship_park:Clone()
			map_1.Parent = game.ServerStorage.maps
		end
	end

the output is 11:57:45.382 - Infinite yield possible on 'ServerStorage.maps:WaitForChild("friendship_park")' 11:57:45.384 - Stack Begin 11:57:45.385 - Script 'ServerScriptService.mainscript', Line 125 11:57:45.386 - Stack End

1 comment

0

WaitForChild has a second optional argument which it the time to wait

1 answer

✓ Accepted answer

Infinite Yield Possible means that the object that you are trying to wait for, doesn't exist. As an alternative, use FindFirstChild, and add an if statement to check whether it exists or not. Example:

local part = game.Workspace:FindFirstChild("Part")
if part then
	print("Found part!")
else
	print("Cant find part")
end

If you use WaitForChild and it returns Infinite Yield Possible, it will stop running the rest of the script, so it's best to use FindFirstChild. Please accept my answer if this helped!

2 comments

0

I don't think that's quite the correct explanation. I think :WaitForChild will yield (that is, nothing after it will execute) until it finds the child. If it never finds it, it will yield forever, thus Infinite Yield Possible. If you give it its optional second argument, a timout value, if that amount of time has passed and it still hasn't found the child, it will return nil.

0

I didn't know that there was a second argument. Thank you.

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