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 <something> == 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
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!