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

What is the purpose of the # in some for loops?

I'm not quite sure what this does, and I think it has something to do with a table. I just want to know the purpose of this. For example, I want to know what #list does in a portion of a follow script that some NPCS use.

local list = workspace:GetChildren()

for i = 1,#list do
--code or whatever
end

1 comment

1

the # is for how long the list is... for example, suppose you have 5 items in a list, then for i=1,#list <-- # is "5" in this case because you have 5 items. Then you can use for i=1,5 to do whatever with it

2 answers

✓ Accepted answer

List is a table, and #list is going to do the "--code or whatever" once for however many values are in the table. The # is just finding how "long" the table is.

works with strings and tables,

with a string, it will return the length of the string as an integer, representing how many characters are in the string

for tables, it will return the highest number index it can possibly return without getting nil,note that it will not work with string indexes

1 comment

0

lol what

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