I'm still rather new to scripting, and from time to time I'll see something like
for i = 1, #players
What does the # symbol mean?
I'm still rather new to scripting, and from time to time I'll see something like
for i = 1, #players
What does the # symbol mean?
The # symbol means that it is the number of children in a table.
So if I wanted to know how many parts are in a model, I can get a table with :GetChildren()
and do something like this.
if #game.Workspace.Model:GetChildren() > 4 then
print("Too many parts!")
end
What this does is it gets the table of all the children in the model "Model", and puts it into a table. Then the # sign counts all the items in the table.
The code above is less practicle for the situation, but it shows what I am saying.
Thank you! Knowing what it does really helps me apply it to what I make.
It also gives the number of characters in a string.
The terminology is a bit incorrect, but this is the gist. Tables don't have 'children', they have 'members'. The pound operator (#) only works on strings and arrays or tables that are partially arrays.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
This question has been asked many times already. You can search for questions pretty easily