Hello, is there a way to put a script inside a seat to know when someone sits in it? I do not need to know who sits in the seat, but just I would like it to call a function when the seat was sat in.
Can you know if a seat is being sat in?
1 answer
Edited with better code sample: Make sure this is a localscript inside startercharacterscripts
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local mostRecentSeat = nil --the most recent seat that the player sat in
humanoid.Seated:Connect(function(isSeated, seat)
if isSeated then
if seat then
print ("The player is now sitting in the seat named "..seat.Name.."!")
mostRecentSeat = seat
end
else
print("The player is no longer sitting in "..mostRecentSeat)
end
end)
10 comments
im going to try this out!
It works! Im just curious, whats the if statement for?
Glad to know. Mind marking my answer as the solution? The if statement checks if the seat is being occupied by anyone (it's not equal to nothing/nil) whenever the seat's occupant value is changed
anyway to know when they getup? and yeah, I will mark your answer when I figure just one more thing out
can you know when the player gets up*
Yeah, there was a better way of doing it and I made a change to the answer to reflect that. The else bit will fire when the player stops sitting.
hey i think theres some issues in the new script, seat doesnt look like its specified so it doesnt know what it is
the seat being specified is the seat variable
Its not printing anything, and there could be an infinite yield on waitforchild
If you mean that it doesn't find any seat while sitting up, the player is not sitting in any seat which is why seat is nil. I edited the post to keep track of the seat that the player was just sitting in / is sitting in. Also, make sure that the script is inside StarterCharacterScripts
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Not asking for a script, just asking if this is even possible