how do I make it so you can reference the local player in a server script?
1 Like
You have multiple ways.
1)With remotes[ from the client to the server] the first parameter on the server would be the local player who fired the event.
2)By using PlayerAdded with a Player parameter,you can do stuff on that player.
And there are more ways
Check out this topic
7 Likes
if I were to use a remote event how would I script it?
--local script on the client:
local rs = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
rs:WaitForChild("MyRemote"):FireServer()
end)
--Server Script
gane.ReplicatedStorage.MyRemote.OnServerEvent:connect(function(Player)
print(Player.Name)
end)
5 Likes
Here, I assume you put the local script under a TextButton in a ScreenGui
Its not possible to get Localplayer and a server script. Only on local scripts. But you can use RemoteEvents as said below. Here’s an example:
Local script:
game.ReplicatedStorage.RemoteEvent:FireServer()
Server script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- The player parameter is the player who fired the RemoteEvent.
end)
If you want more details on RemoteEvents and details on communication between the server and client look here:
4 Likes