Grabbing the player from seat.occupied and using it to :FireClient(player)

Ahoy there! This is my first ever topic on the roblox devforum, nice to meet/work with you all.

Before I explain the problem, here’s some context behind what the script does:
I’ve got a plane with seats. When the plane is about to take-off, I’m trying to make sure that any seated player or player that sits down after this certain moment in time, can no longer stand back up and gets a GUI appearing on their screen explaining why. This would last until I fire the event again. For additional context, the player can only stand up using a proximity prompt, so on the client side of things, I’m disabling the prompt.

My issue is that whenever I try to identify who the player is, and then do :FireClient(), I get an error saying:

FireClient: player argument must be a Player object

The script is stored under the plane model in the workspace (it’s a server script not a local script and I’m trying to avoid making another script to save clutter and a headache). The folder only contains seats.

for _,v in pairs(seatsFolder:GetChildren()) do
	if v.Occupant then 
		local player = v.Occupant.parent

Any help is appreciated!

Occupant refers to the humanoid inside a character in the workspace, meaning that doing seat.Occupant.Parent will return the character instance inside the workspace.

FireClient() needs a Player instance in order to run, which is why you are getting that error because you are trying to pass the player’s character as an argument instead of the player itself.

Instead, I recommend using the :GetPlayerFromCharacter() function like so:

local player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)

Then try passing that into your remote event.

1 Like

Wonderful, this worked perfectly, just needed to define “Players”. Thank you!

For those looking for my solution code:

for _,v in pairs(seatsFolder:GetChildren()) do
		if v.Occupant then 
			local player = game.Players:GetPlayerFromCharacter(v.Occupant.Parent)
			staySeatedEvent:FireClient(player, v.ProximityPrompt)