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.
What is the issue? I don’t know how
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 .
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 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)
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 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.
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)