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

How can I cancel WaitForChild?

Asked by 10 years ago

So I'm doing Workspace:WaitForChild(player.Name) to wait to see if their character spawned. If it doesn't spawn within 60 seconds, I want to stop waiting for child and player:Kick(). How can I do this?

2 answers

Log in to vote
2
Answered by 10 years ago
function customWaitForChild(parent, child, WaitTime)
    local waited = 0
    repeat     
        if waited > WaitTime or parent:FindFirstChild(child) then --If it's been going for too long, or if there is a child with the name specified by child,
            return parent:FindFirstChild(child) --Return the child, if it exists, or nil.
        end
        waited = waited + wait(0) --Add a wait to the time waited
    until nil
end
--Something like this should work, this is untested.
Ad
Log in to vote
-1
Answered by 10 years ago

I don't think that will work. Because the waitforchild waits for the person to spawn but you can't assign it a time I think.

Answer this question