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

How to get a property from GetChildren()?

Asked by
zomspi 541 Moderation Voter
5 years ago
Edited 5 years ago

I am trying to check if the players name is in any one of the values of a folder, I tried something but it didn't work, I have variables set up.

if plr.Name == game.ReplicatedStorage.WaitingNames:GetChildren().Value then

Thanks!

Edit: A bit more detail, WaitingNames is a folder, it has string values in it, a string value represents the player, e.g, 5 players, 5 string values. The value of the string value is the players name, every name / value is different, I use this for making player lists.

1 answer

Log in to vote
1
Answered by
Nefarioum 162
5 years ago
Edited 5 years ago

Hey there.

When GetChildren() returns is a array. So essentially, a table full of whatever you had used the function on. However, in order to actually make use of this table we will need to iterate over it. To do this we will use in pairs iteration. What this will do is for each entry to the table, it will run the code inside once and provide you with variables based on the table.

To do this you will need the following code:

for i, v in pairs(game.ReplicatedStorage.WaitingNames:GetChildren()) do
 -- Code here
end

This will then iterate over each entry generated from the GetChildren(). The i stands for Iteration and v is Value and both are variables we can use in our code. You can name these whatever you want and just act as parameters. Finally, we can use this for your instance by running a if statement check within the iteration.

for i, v in pairs(game.ReplicatedStorage.WaitingNames:GetChildren()) do
    if v.Value == plr.Name then
        print("I found a match!")
    end
end

Hope this helps :)

0
Thanks! zomspi 541 — 5y
0
How do I get the value of the string value though? e.g game.ReplicatedStorage.WaitingNames:GetChildren().Value? zomspi 541 — 5y
0
Oh I see, you'd need to do v.Value to get the value of the actual string object. I'll edit my answer. Nefarioum 162 — 5y
Ad

Answer this question