Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can you know if a seat is being sat in?

Asked by 5 years ago

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.

0
Not asking for a script, just asking if this is even possible guywithapoo 81 — 5y

1 answer

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
0
im going to try this out! guywithapoo 81 — 5y
0
It works! Im just curious, whats the if statement for? guywithapoo 81 — 5y
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 royaltoe 5144 — 5y
0
anyway to know when they getup? and yeah, I will mark your answer when I figure just one more thing out guywithapoo 81 — 5y
View all comments (6 more)
0
can you know when the player gets up* guywithapoo 81 — 5y
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. royaltoe 5144 — 5y
0
hey i think theres some issues in the new script, seat doesnt look like its specified so it doesnt know what it is guywithapoo 81 — 5y
1
the seat being specified is the seat variable royaltoe 5144 — 5y
0
Its not printing anything, and there could be an infinite yield on waitforchild guywithapoo 81 — 5y
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 royaltoe 5144 — 5y
Ad

Answer this question