Infinite yield possible

Hello, I have this error message in my console. My script still works but I’d like to adjust it anyway. Do you have an idea?

Here’s the structure of my script for a Shop:

Capture d’écran 2023-06-15 111013
pprompt of th shop


my UI with the script which has a problem


the console error

here’s the code if you need it

local ProximityPart = game.Workspace.Shops.Illegal_Shop:WaitForChild("ProximityPromptPart3").ProximityPrompt3



ProximityPart.Triggered:Connect(function()

	game.Players.LocalPlayer.Character:GetChildren("Humanoid").WalkSpeed = 0
	script.Parent.Visible = true

end)

An infinite yield basically means there is a possibility of ProximityPromptPart3 (in this case) never being found by :WaitForChild(). This warning exists to make you informed of this. If ProximityPromptPart3 was never found, the script would yield and nothing below it would run in this case.

Do note that is not an error, rather a warning. The script as you stated works, meaning that ProximityPromptPart3 was indeed found by the :WaitForChild() method.

So he finds it according to you, so why is he showing me this then?

It’s just one of roblox’s features to output a warning for debugging purposes. People have made custom libraries for their own :WaitForChild() methods which don’t output this warning.

Looking back at your code and how the game is organised, you might wanna instead call :WaitForChild() on the ‘ProximityPrompt3’ rather than the ‘ProximityPromptPart3’. Are these shops always replicated on the Workspace or do they get spawned in/deleted?

1 Like

shops are in workspace

this causes a rather strange error because it exists

No, you need to do workspace.Shops.Illegal_Shop:WaitForChild("ProximityPrompt3").

A far easier way of supressing this warning is to set a timeout:

Instance:WaitForChild("Name", timeout)
3 Likes