Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does the # symbol mean in ROBLOX Lua?

Asked by 8 years ago

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?

0
This question has been asked many times already. You can search for questions pretty easily BlueTaslem 18071 — 8y

1 answer

Log in to vote
3
Answered by
Azmidium 388 Moderation Voter
8 years ago

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.

0
Thank you! Knowing what it does really helps me apply it to what I make. ShadowsDev 62 — 8y
2
It also gives the number of characters in a string. 1waffle1 2908 — 8y
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. adark 5487 — 8y
Ad

Answer this question