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

What does the # symbol mean in ROBLOX Lua?

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?

1 comment

0

This question has been asked many times already. You can search for questions pretty easily

1 answer

✓ Accepted answer

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.

3 comments

0

Thank you! Knowing what it does really helps me apply it to what I make.

2

It also gives the number of characters in a string.

1

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.