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

How would I use something Similar to waitForChild on a table?

Asked by 4 years ago
Edited 4 years ago

so I insert Players userID inside a table it looks something like this

{1 = "Roblox", 2 = "IDKTHISPLAYER"}

but since this is inserted in player added

I was wondering How I could use something similar to :WaitForChild on a table

It would look something like

Table:WaitForChild(Player.UserId)

But I know for a fact that WaitForChild don't work on a table

0
What are you trying to do? ForeverBrown 356 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

So in your case you'll be waiting for a table to hold a value or player to be added to the table? I would check a table for the existence of a key value, instead of value, in order to make it easier to wait for the existence of playername added to it.

I suppose one thing you could do is run a function that converts your current table structure temporarily so that the values become keys and then do a check for that key... you could then run a loop that returns true when the key is found.

function waitForTableValue(tbl,value,timeout_seconds)
        -- do some checks
        if timeout_seconds==nil or timeout_seconds==0 then
            timeout_seconds = 3 -- default to timeout_seconds
        end
        if value==nil then
            return false
        end
        local start_time = game.Workspace.DistributedGameTime
        -- you could also do a type check on tbl, but below should suffice... just be sure to make tbl a table!
        if tbl==nil or #tbl==0 then
            return false
        end

        local tmptable = {}
        for i,v in pairs(tbl) do
                tmptable[v] = i
        end
        while tmptable[value]==nil and game.Workspace.DistributedGameTime - start_time<timeout_seconds do
            wait(.1)
        end
        if tmptable[value]~=nil then
            return true

        end
        return false
    end
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The ":WaitForChild()" also same as like":FindFirstChild()".

The call ":FindFirstChild()" does as it says. It finds the first child of a parent of which you name it. There must always be an argument, most likely a string. Let's see how it works:

game.Workspace.Figure:FindFirstChild("Humanoid")

If you think I explain too hard, explain not cleary, want to see more information with ":FindFirstChild" , click here.

Also, ":WaitForChild()" is find the thing that doesn't exist at testing mode,when you start the game, the thing will appear at the game. Like this :

local part = Instance.New("Part")
part.Parent = game.Workspace
part.Position = Vector3.new("0,0,0")
game.Workspace:WaitForChild("Part").BrickColor = BrickColor.Random()

If you think I explain too hard, explain not cleary, want to see more information with ":WaitForChild()" , click here.

Hope I helped.Thanks for reading!

0
NOTE : I pretty new from scripting helpers, so I don't know how to make a blockquote XD Xapelize 2658 — 4y
0
I don't think WaitFoChid works on table elements. It doesn't... that's good for game elements.. not data. JasonTheOwner 391 — 4y
0
Oops... I took that saying about the similar of the WaitForChild() , but I doesn't notice about the script is a table element.. Sorry :P Xapelize 2658 — 4y

Answer this question