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

Can you know if a seat is being sat in?

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.

1 comment

0

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

1 answer

✓ Accepted 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

0

im going to try this out!

0

It works! Im just curious, whats the if statement for?

0

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

0

anyway to know when they getup? and yeah, I will mark your answer when I figure just one more thing out

0

can you know when the player gets up*

1

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.

0

hey i think theres some issues in the new script, seat doesnt look like its specified so it doesnt know what it is

1

the seat being specified is the seat variable

0

Its not printing anything, and there could be an infinite yield on waitforchild

1

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.