Help getting the player that fired a remote event from server script

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.

-- Server Script
Prompt.Triggered:Connect(function(player)
	remote:FireClient(player)
end)

--Local Script
remote.OnClientEvent:Connect(function(player)
	print(player.Name)
end)

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:

-- Server Script
Prompt.Triggered:Connect(function(player)
	remote:FireClient(player, player)
end)

--Local Script
remote.OnClientEvent:Connect(function(player)
	print(player)
end)

when I only put player once in the parameters, it doesn’t get the player but this works for some reason which doesn’t really make sense to me

Reason:

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.

2 Likes

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.

1 Like

You can just use Players.LocalPlayer to fetch the local player in a local script, no need to pass an additional player argument.

1 Like

yeah but I need the specific player that triggered the prompt.

1 Like

Isn’t the player that triggers the prompt the client you intend to fire? Or do you intend to fire every client via FireAllClients?

1 Like

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.

no just firing to the specific client

Can’t you connect to the event on the client too then?

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.

1 Like