Why do people do this

Ok.
I need to know why people keep doing this

why do people use seperate functions for like PlayerAdded for example:

Why use this:

local function onPlayerAdded(player)
	print("Hello " .. player.Name .. "!")
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

when you can just use this:

game.Players.PlayerAdded:Connect(function(player)
	print("Hello " .. player.Name .. "!")
end)

??

Is it more optimal? I’m curious

1 Like
  1. Stylistic choice.
  2. They want to use onPlayerAdded elsewhere, like for players that joined before the script started.
2 Likes

@Pokemoncraft5290 said it well, some people organize their code that way,but most people do it because they can use those functions elsewhere without having to create it again. its convenient

u mean that as in 2 playeradded functions?

yes, instead of having to copy and paste the code they can just call it, also they can make it run whenever they want to not only when the player joines

Normally I use the second method if I don’t have to do the same thing somewhere else again. But overall both methods shouldn’t make a difference in performance.

But when people use the first method and only use the function once it kinda triggers me. :skull:

I really love the first method. It look bery stylish.