Search code examples
luaroblox

How to detect when a player sits


I was wondering if there is an easy way to detect when a player sits in a specific chair, other than detecting if the player touches the seat, which doesn't always work.


Solution

  • There is the Humanoid.Seated signal.

    game.Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
    
            -- listen for when the player sits down
            character.Humanoid.Seated:Connect(function(active, seatPart)
                -- active (bool) : true when a player is sitting
                -- seatPart (Instance of Seat or VehicleSeat) : the seat that the player has just sat in or left
                print(string.format("Is %s sitting? %s", player.Name, active and "yes" or "no")
                print("the seat in question : ", seatPart)
            end)
        end)
    end)