How to get the seat the player is on?

I tried this:

local CurrentSeat = LocalPlayer.Character.Humanoid.SeatPart

while wait() do
   print(CurrentSeat)
end

It constantly prints nil , even when I’m sitting on the seat .

Any help is appreciated!

1 Like

you can do something like this.

local seatToCheck = path.to.seat

seatToCheck:GetPropertyChangedSignal("Occupant"):Connect(function()
  local currentSittingPlayerCharacter = seatToCheck.Occupant and seatToCheck.Occupant.Parent
  -- do something with this
end)

That defeats the entire purpose, because I’m trying to get the seat from the character to avoid having to get the seat from workspace.

2 Likes

What is stopping you from getting the seat from workspace?

See this post I made.

When you mention an object property it remains constant, instead, you should just reference the object and mention the property when you plan to use it(for example inside the loop).

local Humanoid = LocalPlayer.Character.Humanoid

while task.wait() do 
	print(Humanoid.SeatPart)
end

That works, but how should I detect if the humanoid.seatPart is not nil and the player is sitting in a seat?

I tried this:

local runService = game:GetService("RunService")
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Seat = Humanoid.SeatPart

local event = runService.RenderStepped:Connect(function()
	if Seat:IsA("VehicleSeat") then
		print("player sitting in vehicle")
	end
end)

But it doesn’t work for some reason.

Because you reference Seat outside of the connection(as mentioned above).

I did this like you mentioned:

local event = runService.RenderStepped:Connect(function()

	local Seat = Humanoid.SeatPart
	
	if Seat:IsA("VehicleSeat") then
		print("player sitting in vehicle")
	end
	
end)

But still nothing prints in the output…

Use the Humanoid.Seated event:

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Seated

It returns both the current sitting state and active seat.

1 Like