How do I detect if a player is sitting on a seat?

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve? I want to detect when players are sitting so i can open a UI when they sit

  2. What is the issue? Include screenshots / videos if possible! I used a .Touched Event and it’s only working for standing on the seat not sitting. i got a problem where my sit script is not printing but when i touch it the seat prints. i want the event to fire when i sit not touch it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Seat = script.Parent
--local UI = game.Players.LocalPlayer.PlayerGui.MainUI.ScreenGui.Frame
Seat.Touched:Connect(function(hit) 
    print(hit)
end)

Hello, so i’m making a script that automatically opens a Gui when the players sit on the chair., but my problem is why is it not working. I used a .Touched Event.

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Seated
event that fires when humanoid is seated

Humanoid.Sit returns a boolean that determines if the humanoid is currently sitting
Humanoid.SeatPart returns the part the humanoid is currently sitting on, or nil.

forgot to add that seats also have a Seat.Occupant property

3 Likes

maybe this is what you’re looking for?

local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant ~= nil then
		--: local plr = game:GetService("Players"):GetPlayerFromCharacter(seat.Occupant.Parent) -- optional if you want the player
		--: rest of code here
	end
end)

edit: this shouldn’t be used in a LocalScript*

12 Likes
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Seated:Connect(function(isSeated, seatPart)
	if isSeated then
		print(seatPart.Name)
	else
		print("Player is no longer seated!")
	end
end)

The Humanoid.Seated event is the correct way to go about achieving this.

5 Likes