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
5 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 5 years ago
Edited 5 years ago
01-- Server Script
02 
03local Players = game:GetService("Players")
04 
05Players.PlayerAdded:Connect(function(Player) -- When a player joins
06   Player.CharacterAdded:Connect(function(Character) -- When the player spawns
07   local Humanoid = Character.Humanoid -- Retrieving the humanoid to get the SeatPart prop
08 
09    Humanoid:GetPropertyChangedSignal('SeatPart'):Connect(function() -- When the SeatPart prop changes
10     if not Humanoid.SeatPart then
11         print('Player left seat')
12        else
13         print('Player sat')
14       end
15     end)
16   end)
17end)

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

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

Answer this question