Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is there a way to check for an infinite yield?

Asked by 6 years ago

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

0
WaitForChild has a second optional argument which it the time to wait User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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 WaitForChildand 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!

0
I don't think that's quite the correct explanation. I think :WaitForChild will yield (that is, nothing after it will execute) until it finds the child. If it never finds it, it will yield forever, thus Infinite Yield Possible. If you give it its optional second argument, a timout value, if that amount of time has passed and it still hasn't found the child, it will return nil. GoldenPhysics 474 — 6y
0
I didn't know that there was a second argument. Thank you. PyccknnXakep 1225 — 6y
Ad

Answer this question