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

How to make a player variable in a normal script?

Asked by
Zelt3q 31
3 years ago

Just a simple question, How to make a player variable in a normal script?

0
I can answer in a minute or so, there's a timer on answering, but you would use game.Players.PlayerAdded pengalu200 65 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

You cannot get the player directly on the server with LocalPlayer, however there are some ways to get the player without it.

Method 1: PlayerAdded This method will get a variable of the player whenever a player joins the game. Example:

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

    print(plr.Name) --this will print the name of all players who join.

end)

Method 2: RemoteEvent This method allows the client to send a message to the server (local script to server/normal script). Said message has arguments, and the first argument will always be the client (aka player) who sent it. Example:

--in a localscript
game.ReplicatedStorage.Remote:FireServer()


--in a normal/server script
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(plr)
    print(plr.Name) -- will print whatever client sent that event.

end)
Ad

Answer this question