Hi,
Im trying to get the player that fired a remote event from the server. So basically what this does is when you trigger a proximity prompt, hit fires a remote event from the server, but how would I get the player that fired it from the local script.
-- Server Script
Prompt.Triggered:Connect(function(player)
remote:FireClient(player)
end)
--Local Script
remote.OnCLientEvent:Connect(function()
--Code here
end)
Now I know that triggering a prompt automatically gives you the player so I fire the remote to the player that triggered it, but I want to get the player that triggered it in the local script as well.
yeah that doesn’t work for some reason but I figured something out myself, since firing a remote to a specific client needs the player that its firing to , you need to put player twice in the parameter this is what works for me:
When you do FireClient(Player), it just specifies to which people should be part of that. Meaning, that argument is just for letting the script know which client should get that event.
So, it should be like this:
event:FireClient(Player,args)
And on client:
event.OnClientEvent(args)
If you want to do something with that player on the client, pass it again in the FireClient call.
If you are using a proximity prompt for this, you do not need a remote event. Just connect the Prompt.Triggered event on the server, and the first argument will be the player who used it.
something on the client needs to happen though I need a remote event to make something on the client happen and for that thing to happen on the client, I need the specific player.
Right, so you don’t need the additional player argument.
--SERVER
local function OnTriggered(Player)
RemoteEvent:FireClient(Player)
end
Prompt.Triggered:Connect(OnTriggered)
--LOCAL
local Game = game
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer --This is a reference to the local player of the client that was fired.
local function OnRemoteEventFired()
--Code.
end
RemoteEvent.OnClientEvent:Connect(OnRemoteEventFired)
Additionally, as suggested here a prompt’s Triggered event/signal can be listened for on the client.