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

I wanted to understand the use of * For * and * # * before some variable?

I wanted to understand the use of * For * and * # * before some variable,for example:

local teleporte = script.Parent

function onClicked()
   
local p = game.Players:GetChildren()
for i = 1, #p do
p[i].Character:MoveTo(Vector3.new(-55.831, 11.008, 183.894))
teleporte.ClickDetector.MaxActivationDistance = 0

		
end
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

I wanted to understand how to use and the use of them

1 comment

0

for is a keyword used to start a for iterator loop and # returns the length of either a given table or given string

2 answers

[#] - Operator - This returns either the length of an string or the length of a table.

local Table = {'hi', 'there', 'world'}
print(#Table)
-- Output : 3

[*] - Operator - This is the multiplication operator.

local NumberVar = 10
print(NumberVar * 5)
-- Output : 50

[For] - Syntax - This is used in For Loops in lua to iterate through tables, string functions that return a table (ex: string.split), numbers, etc.

for Iteration = 1, 10 do 
    print(Iteration)  -- prints from 1 to 10
end

Hope this has cleared the questions of yours, if you have any more feel free to ask me.

If you put # right before a table it will represent a number of how much objects are on that table, * is for multiplication. Example:

print(5 * 2)

That will print 10.

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