So basically I am trying to get the player from a server script but I just cannot get it. Does anyone know how to do this?
✓ ANSWER ACCEPTED
How to get the player from a server script?
3 answers
✓ Accepted answer
There are multiple ways to get a single player using server. Remote events and in pairs loops. I'll show you both ways.
In Pairs Loop
for _, v in pairs(game.Players:GetPlayers()) do
end
PlayerAdded Event
game.Players.PlayerAdded:Connect(function(plr)
end)
Remote Events (Note: You should only use Remote Events IF you're gonna use GUIs and stuff, so I do not use recommend using it.)
--Local Script--
local remoteEvent = game.ReplicatedStorage.RemoteEvent
remoteEvent:FireServer(game.Players.LocalPlayer)
--Server Script--
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
end)
Also you can use game.Players:GetPlayerFromCharacter() on certain events such as the Part.Touched event.
A serverscript doesnt work local, try it in a localscript.
1 comment
0
You can get a player instance from the server
game.Players.LocalPlayer
1 comment
0
That would not work as it would return nil.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I usually use that too.