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

what are parameters and what do they do?

2 answers

A parameter is a special instance that a function could have. For example:

local Players = game.Players

Players.PlayerAdded:Connect(function(Player)
print(Player.Name)
end)

In the code above it will print the name of any player that joins the server. The parameter can be named whatever but in the player added event it will always be the player that is added. You can try the script out for yourself if you want to play around with it. Second Example:

local Part = script.Parent

Part.Touched:Connect(funtion(Hit)
Hit.BrickColor = BrickColor.Random()
end)

In the example above Hit is the part that touches the scripts Parent. You can always check if a function has a parameter by looking at the object browser in the view menu.

3 comments

0

that would be an argument, as opposed to a parameter

0

oops

0

I'm not sure if theking48989987 is correct on that. A parameter is the variable declared in the method's definition (the general/universal instance), whereas an argument is a specific instance that is passed to that method.

Below is an example:

game.Players.PlayerAdded:Connect(function(player)

In the example above, 'player' is the player that joins the game.

If we wanted to use the parameter to print the player's name then we would do the following.

game.Players.PlayerAdded:Connect(function(player)
print(player.Name)



The above script would print the player's name into the output

'player' could also be called plr, it doesn't matter. However remember that we would have to say the following:

game.Players.PlayerAdded:Connect(function(plr)
print(plr.Name)

1 comment

0

You forgot the "end)" in those events lmao

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