How can I get the children of a value, so I can see how many players are in the table.
game.ReplicatedStorage.WaitingTeam.OnServerEvent:Connect(function(plr)
local piwt = {}
table.insert(piwt,plr)
-- Here to get the children
end)
How can I get the children of a value, so I can see how many players are in the table.
game.ReplicatedStorage.WaitingTeam.OnServerEvent:Connect(function(plr)
local piwt = {}
table.insert(piwt,plr)
-- Here to get the children
end)
If you wish to iterate though each element of an array, you can use a pairs loop to traverse through the passed table. To demonstrate this, let's create an arbitrary array of elements and shift it's contents into a secondary table:
local Table1 = {"Hello", "world", "!"}
local Table2 = {} do
for _,Element in pairs(Table1) do
table.insert(Table2, Element)
end
end
print(table.concat(Table2, ' ')) --> Hello world !
if you wish to find the length of the array, you can use the hash # length operator.
print(#Table2) --> 3
No you can't get the "Children" of the table, because a table does not have "Children". However if you want to know how many entries are in a table you can just find the length by doing
#piwt -- which is going to equal to the number of entries in that table
However, if you want to iterate through the entries in the table you do
for i, v in pairs(piwt) do
-- code
end
Hope I helped, please let me know if you have any questions.
Thanks for copying me^•^
Edited my answer after rereading the question and rereading my answer, as I always do, did not even know someone else answered, however if you wish to believe that I couldn't have came up with that by myself then do so
Then why be so angry? There is also nothing wrong with my post, so I don't understand why you went through your way to discredit me?
I didn't downvote you work at all, why be so bold to assume it was me?
How was I being rude sir? I simply stated that you copied me, but it turns out I was in the wrong, my apolgies. But I am standing my ground that I in no way shape or form showed any disrespect to you.
Possibly because of your comment on my post, but im guessing it was the poster, I appologize
No worries, I'll upvote you to get your reputation back!
Who was downvoting?
I'm not sure, either the poster or onlookers?
Not sure, it was a misunderstanding
Its -2 and I upvoted it...
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
btw, would my script work to have more than 1 player?
What do you mean?