Are Infinite Yield Possible Warnings Bad?

A lot of my scripts are set so that they don’t work unless the player spawns in a Pizza model into the workspace. To do this I used waitforchild(“Pizza”) and everything seems to work fine gameplay-wise. However, whenever I launch a test in studios I keep getting spammed:

Infinite yield possible on 'Workspace:WaitForChild(“Pizza”).

I’m wondering if this will cause an issue in any aspect of the game and if I should try and fix it or just leave it as is?

2 Likes

I’m not so sure but i believe they’re not very good, and can cause a good amount of lag.

Hope this helps :+1:

4 Likes

The warning occurs when Instance::WaitForChild has waited for over 5 seconds and you didn’t provide the second optional argument, the timeout. “Infinite yield possible” just means there is a chance your script might wait forever for pizza to appearn.

4 Likes

The debugger is basically telling you that the WaitForChild call may wait infinitely due to the fact that it hadn’t found the instance within a certain amount of time. Make sure the instance actually exists and the name corresponds with the WaitForChild call.

2 Likes

The waitforchild argument is inside clickdetectors. Should I change it to findfirstchild so this doesn’t happen.

1 Like

Sure but then Instance::FindFirstChild will return nil if there is no instance with the given name.

Take metryy’s advice:

2 Likes

Basically the clickdetectors spawn ingredients for the player’s pizza and it only spawns those ingredients if a pizza exists. So I understand where metryy is coming from but what would be the best solution here since I can’t actually make sure that the pizza actually exists before the player clicks the buttons?

1 Like

The best solution would be to check if the pizza exists during the click.

Within your clickdetector connection, if FindFirstChild"Pizza" ~= nil (just FindFirstChild"Pizza" alone also works as a conditional itself), you’d run the rest of the code.

3 Likes

Use the ChildAdded event to get a reference to the instance you’re checking for in your scripts.
Capture

3 Likes

Yeah this is what I was thinking too. Thanks.

1 Like