Would this method work for getting the local player in a Server Script?

I have a “utils” module in my game used primarily for server scripts, and I made a function to get the player, which invokes a BindableFunction;
image
which is connected to a server script, inside a PlayerAdded function;

This has worked well for now as I’ve been playtesting solo, but I wonder if doing this would actually just return a random player instead of the local player, since the BindableFunction’s callback is in every player’s PlayerAdded function

If that is the case, then what would be a better way to get the player from the server?

1 Like

In what context are you looking for a “local” player on the server?

This is actually pretty funny and interesting. I’ve tried it and it seems to pick one of all players and return that one player for everyone.

test.rbxl (64.8 KB)

It picks the last player that joins because of the way your code is structured.

Basically the same thing you’d get in the client with Players.LocalPlayer, but in the server

  1. There is no LocalPlayer on the server.
  2. You are overriding OnInvoke every time a player joins, getting the latest player.
  3. All the players are under the Players service. Why would you need to do something like this?

That doesn’t make sense… The server is not a client, it does not have a player, it cannot have a player, a local player corresponds to a clients player.