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

Is there a way to open a GUI when a player sits in a seat?

Asked by 8 years ago

Anyone have a way where I can detect when a player sits in a seat, and then open a GUI. When they get up from the seat, it closes?

0
Yes. JamesLWalker 297 — 8y
0
Yes.[2] LegitimatlyMe 519 — 8y

1 answer

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

You could use a Changed event to detect when the occupant property of the seat changes to a new humanoid. When the property is nil, the seat is empty. When someone sits in the seat, the occupant property gets set to that player's humanoid.

Example

local seat = LOCATION_OF_SEAT

seat.Changed:connect(function(property)
    if property == "Occupant" then
        local humanoid = seat.Occupant
        local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
        if player then
            -- code
        end
    end
end)
Ad

Answer this question