How to detect seat occupant?

Hello! I am trying to find out when a vehicle seat obtains an occupant and then want to get that players mouse. I am not sure on how to do this, but I did try this:

local occupant = script.Parent.Occupant
local mouse = game.Players:GetPlayerFromCharacter(occupant)

while true do
	wait()
	if occupant ~= nil then
		print(occupant.Name)
	end
end

The script returns nothing.

Thanks in advance for helping! :grinning_face_with_smiling_eyes:

5 Likes

The player is

game.Players:GetPlayerFromCharacter(occupant.Parent)

This is because the occupant is the player’s character’s humanoid, not the character.

5 Likes

What @Aeventy said is correct, and also, to just detect the occupant of the set you can use GetPropertyChangedSignal on the Occupant property

local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if not hum then return end
	
	local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
	if not plr then return end
	
	print(plr.Name)
end)

Is a way to do it

15 Likes

This worked, Thank you! And thank you too @Aeventy

5 Likes

Anytime! If you have anymore issues don’t be afraid to make another post!

5 Likes