Can "Infinite yield" errors cause a problem to your game?

Hello there :wave:,

  1. What do you want to achieve? Remove the Infinite yield error from Output – if the Infinite yield won’t cause any harm to the game, then that’s ok, i’ll just leave it there.

  2. What is the issue? I don’t know how :sweat_smile:

  3. What solutions have you tried so far? Removing "WaitForChild("Instance")"

I have been getting multiple "Infinite yield" errors because of the presence of "WaitForChild("Instance")" in some script and the scripts seems to work fine but when i change the "WaitForChild("Instance")" into "script.parent.Instance"(example) the script no longer works. Any help would be appreciated :+1: .

it doesn’t work probably because the object you indexed didn’t load before the script

:WaitForChild() would wait for an object to load before running the rest of the script

the only way it’ll infinitely yield is if the parent doesn’t have the object, the object’s name was misspelled, or the object isn’t real

2 Likes

But the error appears while using :WaitForChild()

1 Like

well what exactly did you do
(:WaitForChild() isn’t broken)

1 Like

I must note that this isn’t actually an error, but rather a warning, and can be ignored if it doesn’t break functionality.

I would also mention that its likely you could be overusing waitforchild, as its only truly necessary on the client and under specific situations

1 Like

the script below is a local script located in StarterPlayerScripts.
here is the error (line 3) : Infinite yield possible on 'Workspace.Level5:WaitForChild("LowerCamOnTouchLv5")'

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local touchPart = workspace.Level5:WaitForChild("LowerCamOnTouchLv5") -- Change "TouchPart" to the name of your part
local targetZoom = 20 -- Set the desired zoom distance when touched

-- Function to lower zoom
local function lowerZoom()
	player.CameraMaxZoomDistance = targetZoom
end

-- Connect the Touched event
touchPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		lowerZoom()
	end
end)

I have no other choice but to use it for the script to work

I see, in this case it is necessary due to streaming-enabled. you have three solutions here if you don’t wanna worry about the warning:

  1. Turn off streaming-enabled, you can find this under workspace properties
  2. group the part as a model, and set the model’s ModelStreamingMode to Persistent
  3. ignore the warning (but having infinite yielding code is generally not a good practice)
1 Like

I don’t want to mess with stuff i don’t understand :sweat_smile: :

Guess i’ll just ignore it, Thank you so much :slightly_smiling_face: .

I would actually recommend turning streaming-enabled off if you’re learning, that feature makes localscripts more complicated and you have to design your game around it
(you will experience this issue everytime you want to grab an object in workspace from a localscript)

1 Like

i have asked an ai what are the consequences of turning it off and he said this:

  1. Increased Memory Usage
  2. Lag and Performance Issues
  3. Reduced Visibility
  4. Script Errors
  5. Limited Gameplay for Mobile Users:

and that it can also lead to this:
image

streaming enabled is what leads to the gameplay paused screen. (if you decide to enable the paused feature)

all that streaming enabled does is unload objects that are far away
(which means you can’t access them from local scripts, and have to wait for them)

it also isn’t a direct improvement over not using it, you’re improving performance at the cost of network load (server has to send objects to all the players as they get close to them, can lead to lag)

this feature is a common cause of confusion for learning developers, be aware that you will also have to handle the scenario where your player walks away from your part, and it stops existing for them.

also these are untrue :sweat_smile: its actually the OPPOSITE on the case of visibility. (since you know, it unloads far away objects)

also, the performance benefits aren’t that significant unless you have big environment with many parts, models & terrain.

I guess, I will try it.

[Extra words for 30 letters]

What are the bad consequences on enabling it?

enabling it means you will experience the waitforchild warnings, have to handle when the part exists and when it stops existing (due to going too far from it)

disabling it means you won’t have to worry about this as the world is fully loaded at all times.

I am recommending you to disable it (you currently have it enabled)

2 Likes

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