Hi, I would like to know which of the options below is the best for detecting when a player enters the game. Then I know immediately which one I will use from now on.
Option 1:
local Players = game:GetService("Players") local function PlayerAdded(Player) end Players.PlayerAdded:Connect(PlayerAdded)
Option 2:
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(Player) end)
local Players = game:GetService("Players") local function PlayerAdded(Player) end Players.PlayerAdded:Connect(PlayerAdded)
I really like the idea of this design and it would probably be cleaner. Performance-wise I think that option 2 would load quicker because it doesn't have to go through the function before the event if you know what I mean
They are very similar and in this case, they complete the same tasks. However option 1 allows many different events to fire that one function while option 2 only allows one single event to fire that specific function. For example: Option 1
local function SayHi() print("Hi") end game.Players.PlayerAdded:Connect(SayHi) game.Players.PlayerRemoving:Connect(SayHi)
This would print Hi when the player leaves AND joins.