I have to perform some specific functions if the player is the first one on the server.
From the second player onwards, I don’t need to perform these functions.
What is the best way to check if the current player is the first player to join the server?
1 Like
That’s how I would do it.
old
``` local players = game:GetService("Players") local firstPlayerplayers.PlayerAdded:Connect(function(plr)
if #players:GetPlayers() == 1 then
firstPlayer = plr
end
end)
1 Like
Actually, this is probably faster and more reliable:
local players = game:GetService("Players")
local firstPlayer
players.PlayerAdded:Connect(function(plr)
if not firstPlayer then
firstPlayer = plr
end
end)
1 Like
Thanks, but actually I think the 1st solution is the simplest, because if GetPlayer == 1, and it’s the player that’s testing it, there’s no way it can be another player.
Yes but the second solution is faster since you don’t have to call :GetPlayers()
and it works the exact same way. You can simplify it if you want - firstPlayer = firstPlayer or plr
.
1 Like
Yeah, you’re right. Thanks you.