Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if seat is occupied or not?

Asked by
ka3r 14
4 years ago

How do I detect if a player sat on a seat and when the player leaves?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
-- Server Script

local Players = game:GetService("Players") 

Players.PlayerAdded:Connect(function(Player) -- When a player joins
   Player.CharacterAdded:Connect(function(Character) -- When the player spawns
   local Humanoid = Character.Humanoid -- Retrieving the humanoid to get the SeatPart prop

    Humanoid:GetPropertyChangedSignal('SeatPart'):Connect(function() -- When the SeatPart prop changes
     if not Humanoid.SeatPart then 
         print('Player left seat') 
        else 
         print('Player sat')
       end
     end)
   end)
end)

Hope this helps. Anything else you need make sure to ask me.

1
Great answer. Much more efficient than Seat.Occupant. DeceptiveCaster 3761 — 4y
Ad

Answer this question