Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a player variable in a normal script?

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

1 comment

0

I can answer in a minute or so, there's a timer on answering, but you would use game.Players.PlayerAdded

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.