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

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

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

✓ Accepted answer

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 :)

1 comment

0

Thank you for the help, I greatly appreciate it!

This discussion is preserved as it was. New answers, comments, and votes are closed.