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

how do functions know what to identify the variables in the parentheses?

so i have been trying to understand functions and i know the small parts such as executing the function but what confuses me is how the function knows what to identify in between the ()

i have seen some functions with different words such as (part) or (otherpart) but i dont know how the function identifies them

can someone explain this to me please?

1 comment

0

Look up Arguments & Parameters in Lua to get a better understanding.

1 answer

✓ Accepted answer

Basically when you fire the function, it those variables will be the same thing as the ones passed as the arguments.

local function testFunction(argument1,argument2,argument3)
     print(argument1,argument2,argument3)
end

Those three arguments will change their value based on what is passed on when you fire the function:

testFunction("foo","bar","obama")

if we pass those values, argument1 will be "foo", argument2 will be "bar" and argument3 will be "obama".

testFunction("aNormalString","anotherString","aVeryRandomString")

that will make argument1 be "aNormalString", argument2 be "anotherString" and argument3 be "aVeryRandomString".
But we can send a lot of things, not only strings. This is an example where we can modify a part:

local function modifyPart(part,name,color,canCollide)
     part.Name = name
     part.Color3 = color
     part.CanCollide = canCollide
end

modifyPart(game.Workspace.someRandomPart,"aNewName",Color3.fromRGB(255,255,255),false)

As you can see, we are firing a Instance (the part), a String (the name), a Color3 (color) and a Boolean, (the CanCollide property).
Quick note:

  • The variables inside the function can be named whatever you want, they will still remain the value they are fired with.

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