What are function parameters? Help needed I dont understand them

I have recently been interested in lua scripting , I understand most of the stuff but I dont understand function parameters.

Like for example while writing functions for a leaderboard:

local function <u> onPlayerJoin(player) </u>

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    <u> leaderstats.Parent = player </u>

end

I have marked the areas where I’m confused by using the HTML <u.> element.

I really don’t understand why it’s been used here neither do I know what it’s used for. I’m looking for a well defined answer that clears my doubt( what are parameters , what are they used for , some other examples of scenarios where they would be used etc.) .

( I do have a good idea on programming in general , so I don’t need an explanation as you would explain to a complete beginner )

I have tried watching Youtube videos , but they dont explain it too well for me to understand.

Thank you,
Orginatix

Parameters are basically placeholders that are passed on with functions in the brackets as show here,

Some functions force a parameter such as game.Players.PlayerAdded:Connect(Function(Player)

As you can tell the forced parameter for the .PlayerAdded function is Player, and that is the player object found in the players folder in the explorer.

now that’s the first type of a parameter passed on the second type can be given out like this

function small(Word)
   print(Word)
end

small("Small")

I hope you find this helpful

this link can go more in depth. Parameters and events

2 Likes

I think I kind of understand it now so parameters are the objects the function affects?

for examples if the function is onPlayerJoin then the parameter would be player

and for a function add,the parameter would be numbers?

1 Like

It depends on your function really and what you want to achieve but yeah that’s correct for the most part

1 Like

Great! Thanks for helping!! :slight_smile:

1 Like