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.
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 :)