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

How do I make a GUI turn off after leaving a seat?

Asked by 7 years ago

Hi, I'd like to ask how would I make so when I leave a seat, the GUI that was turned on when entering the seat turns off.

My small code so far that turns on the GUI:

game.Workspace.Seat:WaitForChild("SeatWeld")
game.Players.LocalPlayer.PlayerGui.seatgui.Frame.Visible = true

1 answer

Log in to vote
0
Answered by 7 years ago

A better way to do this is to listen for the "Occupant" property of the seat being changed. Here's how it should look:

local seat = workspace.Seat

function SeatChanged(propertyChanged)
    if propertyChanged == "Occupant" then
        if seat.Occupant then
            game.Players.LocalPlayer.PlayerGui.seatgui.Frame.Visible = true
        else
            game.Players.LocalPlayer.PlayerGui.seatgui.Frame.Visible = false
        end
    end
end
seat.Changed:connect(SeatChanged)

What this code does is connect the SeatChanged function with any property of the seat being changed. From there, it checks if the property that was changed was "Occupant", which is the player when the seat is occupied. Then, it simply checks if the player exists in that property; If not, it closes the GUI, if so, it opens it.

If I've helped you, be sure to mark my answer correct :)

0
Thank you for the help, I greatly appreciate it! GlobeHousee 50 — 7y
Ad

Answer this question