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:

1game.Workspace.Seat:WaitForChild("SeatWeld")
2game.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:

01local seat = workspace.Seat
02 
03function SeatChanged(propertyChanged)
04    if propertyChanged == "Occupant" then
05        if seat.Occupant then
06            game.Players.LocalPlayer.PlayerGui.seatgui.Frame.Visible = true
07        else
08            game.Players.LocalPlayer.PlayerGui.seatgui.Frame.Visible = false
09        end
10    end
11end
12seat.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