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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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

1
Wow, thanks man! That explains allot! TheeDeathCaster 2368 — 10y
0
Glad I could help! AmericanStripes 610 — 10y
Ad
Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago

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..

Log in to vote
0
Answered by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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

Answer this question