✓ Accepted answer
When firing a remote event from the server to the client, the only necessary argument is the Player object. However, this is only used in order for the server to know which client to specifically send the information to: which means that the argument is not actually passed to .OnClientEvent:Connect(function().
If you want to get the player on the client, you can either use Players.LocalPlayer:
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Event = ReplicatedStorage:WaitForChild("Event")
local LocalPlayer = Players.LocalPlayer
Event.OnClientEvent:Connect(function()
print(LocalPlayer.Name)
end)
OR you can pass a second argument through the remote event, which is the same Player object:
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Event = ReplicatedStorage:WaitForChild("Event")
Players.PlayerAdded:Connect(function(newPlayer)
wait(1)
Event:FireClient(newPlayer, newPlayer)
end)
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Event")
Event.OnClientEvent:Connect(function(LocalPlayer)
print(LocalPlayer.Name)
end)
Either of these methods should work fine. Personally I would use the LocalPlayer method, because it means the RemoteEvent won't need to send extra information to the Client that the Client can easily get itself.
If you still need more help, feel free to ask!
-Poe
1 comment
Thank You.