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

I can not figure out why the # is needed in this script?

I have been using this for a while now, but I don't really understand why its been using like this, heres an example;

c=workspace:children()
for i=1,#c do --The # is what I don't understand, what is it used for?
if c[i].className=="Part"then
c[i].Anchored=true
end end

4 answers

You can think of the # as something that says *The amount of * ..Whatever is next

So in the script your provided, it is how many parts/objects are inside Workspace.

So if your workspace looks like:

Workspace
	- Terrain
	- Script
	- Model1
	- Model2
	- Model3

and you had:

local number = #Workspace:GetChildren()

Number would equal 5

2 comments

1

Wow, thanks man! That explains allot!

0

Glad I could help!

The # in the script basically stands for number of as in this script

c=workspace:children() -- This is children of workspace
for i=1,#c do -- The #c stands for every number of childrens inside workspace do this or that
if c[i].className=="Part"then -- In this case it does it to parts in workspace only
c[i].Anchored=true -- it anchors the number of parts in workspace
end end

I hope you understand this because it's really important later on..

I always think of it as "Number C" or "Number Workspace" because it lets me imagine that this equals the NUMBER of Workspace.

`# means Number Of Like print(#game.Players:GetChildren()) Would print the amount of players.

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