Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i detect if the player sit in a specific seat?

I need to have a script to add 100 bucks every time he sits in it so far i have this:

local Player = game.Players.LocalPlayer
local stats = Player:WaitForChild("leaderstats")
local money = stats:WaitForChild("Money")
repeat wait() until Player.Character ~= nil and
workspace:FindFirstChild(Player.Name)
local Character = Player.Character
local Humanoid = Character:Waitforchild("Humanoid")
local Seat = game.Workspace.GasStation.JobSeat.Seat


local debouce = true


Humanoid.Changed:Connect(function()
	if Humanoid.sit == true and Humanoid:GetState()== Enum.HumanoidStateType.Seated and debouce == true then
		debouce = false
		print("It Worked")
		money.Value = money.Value + 100
	elseif Humanoid.sit == false and Humanoid:GetState() ~= Enum.HumanoidStateType.Seated and debouce == false then
		debouce= true
	end
end)

1 answer

You seem to be using quite dated techniques to get the seat status of a Humaoid.

You can use :GetPropertyChangedSignal() with the SeatPart property of humanoid to achieve this.

GetPropertyChangedSignal() is like Canged() but only fires for the given property so is more efficent as it isn't always forced to process.

So...

Humanoid:GetPropertyChangedSignal("SeatPart"):Connect(function()
	if Humanoid.SeatPart == path.to.specific.seat.instance then
		money.Value = money.Value + 100
	end
end)

Or you could check the Occupant property of the seat itself, which will give the humanoid.

This discussion is preserved as it was. New answers, comments, and votes are closed.