Seat not printing when child added

I’m trying to get the player of the person that sat down in the seat but it’s not working correctly
code:

script.Parent.ChildAdded:Connect(function()
	local player = game.Players:FindFirstChild(script.Parent.SeatWeld.Part1.Parent.Name)
	print(player.Name)
end)

the script is in the seat

You could check whenever the “Occupant” property of the seat is changed through GetPropertyChangedSignal.

local seat = script.Parent -- assuming

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    local human = seat.Occupant
    if human then
       local player = Players:GetPlayerFromCharacter(human.Parent) -- actual player
       if player then -- might fire for NPCs I believe, so check if this is a player's humanoid
           print(player.Name)
       end
   end
end)

The Occupant is the players humanoid?

Yes, the value is either a player’s/NPC’s humanoid, or nil, if no one is currently sitting on it.

1 Like