How to define the player for a Remote Event?

  1. What do you want to achieve? To define the player for the remote event to execute.

  2. What is the issue? I can’t find a way to specify the player that got out of the seat.

  3. What solutions have you tried so far? I have searched everywhere throughout the DevForum and even other websites and I couldn’t find anything.

Script:

local Seat = game.Workspace.Chair.Seat
local RemoteEvent = game.ReplicatedStorage.RemoteEvents.CamSeat
local RemoteEvent2 = game.ReplicatedStorage.RemoteEvents.PlayerCam

Seat.Changed:Connect(function()  
	if Seat.Occupant ~= nil then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
		RemoteEvent:FireClient(Player)
	else
		local Player = game.Players:GetPlayers()
		RemoteEvent2:FireClient(Player)
	end
end)

Basically I want a remote event to execute when the player gets out of the seat, and the only way I know how is to specify the player. But I can’t because the only way to specify them is to see if the seat is occupied by said player (which I can’t do since the player got out of the seat)

I don’t know any other ways to execute the remote events. But as always, any help is very much appreciated!

When a client is firing a server RemoteEvent, the first argument is always the Object of the player who fired that event. Even if there isn’t a argument.

See : RemoteEvent | Roblox Creator Documentation

Furthermore, in this case, selecting a player using an argument other than the one defined to indicate who triggered the remoteEvent could be used by cheaters to trick the server into thinking that “that player” has left the seat, thus causing abuse and possibly disrupting the game experience of the user in question.

Just store the Occupant in a currentplayer object. There is a code example at the documentation here.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.