Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Get Player on a Server Script?

Asked by 6 years ago
Edited 6 years ago

You can get the player on a localscript using

game.Players.LocalPlayer

but how do you get the player on a Server Script without using this function below.

game:GetService('Players').PlayerAdded:connect(function(player)

end)

This function only gets the latest player that joins the game. How do I get only the Player, currently playing the game on a server script, just how LocalPlayer works?

0
Thank you appreciate the answer. peacepartystudios 9 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

There is no way, it's called a server script. You could use a remote event to get it from the client. Some other ways though

for index, player in pairs(game.Players:GetPlayers()) do
    -- script
end

This runs for all players

or this one

game.Players.PlayerAdded:connect(function(plr)

end)

This is probably your best option as it is pretty much the same as a localplayer. This does NOT only gets the latest player.

There is no other option if you don't know the way, your best option would be 'remote events' even if you hate it like a lot of people :/

Ad

Answer this question