Still have questions? Join our Discord server and get real time help.
3

# what is the meaning of the () after the function even?

i never understood the parenthesis on function ()

what is it for because i don't understand when we put values in it.

0
They are called parameters. Jessesong 1408 — 8d

3
Edited by RubenKan 8 days ago

The brackets at the end of function() are there for parameters to be put in. Parameters are basically pre-determined values within a function to make them more dynamic, say for example, you'd like to name 2 Instanced parst for example, instead of writing 2 different functions, you could just do:

function GeneratePart(PartName) -- This is a 'Parameter'
local Part = Instance.new("Part")
Part.Name = PartName
end

GeneratePart("wahiodhawidh") -- This is an 'Argument'
GeneratePart("asufhauwihdu")


The code above would generat two parts but with differnet names, the names would be the ones stated in the argument

I hope this explination helped, some YouTube videos are out there for further explination.

2
A thing I would like to point out, you're using a parameter and a variable with the same name. It will cause confusion with the script, and it will break itself. So use a different variable name or parameter name. Dovydas1118 767 — 8d
0
wow im so dumb i meant to put name as the parameter jaackharm 42 — 8d
1
AlvinBlox’s tutorial huh... iivSnooxy 215 — 8d
0
mhm caught rrreeeeddd handed goodlead 23 — 8d
0
f Gooncreeper 79 — 8d
0
f Gooncreeper 79 — 8d
2
Edited 8 days ago

So basically the () on the function are parameters, So say this is our script

function Test(myParameter)
print(myParameter)
end


So the () are for storing parameters which are basically Variables, but what the cool thing is that you can send them when firing the function. So here is a example:

function Test(myParameter)
print(myParameter)
end
Test(123)


This script would print 123 as when we fired the function we put the first parameter as 123. We can also have multiple parameters

function Test(myParameter, stringValue)
print(myParameter)
print(stringValue)
end
Test(123, "Test")


This here would print 123 and test, we can send values such as numbers, bools, strings, tables, and even variables, here is a example of sending all 5 over

function Test(numberValue, stringValue, boolValue, myTable, variable)
print(myParameter)
print(stringValue)
print(boolValue)
print(myTable)
print(variable)
end
RandomTable = {"Hello", 123, true}
myVariable = "This String"
Test(123, "Test", true, RandomTable, myVariable)


This would print, 123, "Test", true, Jambled Letters (Unless table value is defined such as MyTable[1] which in that case would print "Hello"), and "This String" I hope you found this useful.

-3

hi, software engineer here. In most if not all programming languages the functions are followed by those parenthesis. First we need to understand for what functions are for:

Functions fulfill the purpose of calling a code whenever you want, you can use this to either short the code (in case you would need to do a certain action several times) or in case you only want the code to be compiled later on and not as soon as its ran.

They can be called from anywhere within the script and are not necessarily static, meaning the action that they do may not actually always be the same, and there is where the parenthesis come in. Parenthesis are variable holders, they accept a variable and store it locally in order to do a certain action, lets show this by an example:

function Sum(a, b)

return a + b

end

--Call the function
Sub(1, 2)

--Output: 3



As you can see, when you call a function you can send values within the parenthesis, this values are passed to the parameters that you see following a function name.

Important detail: variables that you send into a function only exist inside of that function, if you dont send any value the variable (in this example a and b) will just stay as "undefined" or "nil".