Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get the children of a table?

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)

2 answers

✓ Accepted answer

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

2 comments

0

btw, would my script work to have more than 1 player?

0

What do you mean?

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.

12 comments

1

Thanks for copying me^•^

1

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

1

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?

1

I didn't downvote you work at all, why be so bold to assume it was me?

1
  1. Because you were being rude 2) Because you downvoted my post for no reason
1

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.

1

Possibly because of your comment on my post, but im guessing it was the poster, I appologize

2

No worries, I'll upvote you to get your reputation back!

0

Who was downvoting?

1

I'm not sure, either the poster or onlookers?

1

Not sure, it was a misunderstanding

0

Its -2 and I upvoted it...

This discussion is preserved as it was. New answers, comments, and votes are closed.