How would I impliment gui into a vehicle

I want to make a fly button for a car so it can drive and fly. The problem is that I don’t know how to make a vehicle respond to a gui.

The way I want it is for the gui to be parented to the car until a occupant is present. I’m not sure how to make the local script and server script communicate which is the problem.

I’m also curious on the best way to organize this.

You can insert a SurfaceGui into the StarterGui, then set the Adornee to the part where you want the GUI to appear. After that, insert a local script inside the GUI to handle everything you need, and use RemoteEvents to communicate between the client and server.

1 Like

Yeah that would be the best solution for this

why a surface gui?

SurfaceGuis don’t appear in StarterGui

You need to the set the Adornee to the part you want the SurfaceGui to appear.
Screenshot 2025-01-12 192133

I’ve tested it on a part and a frame showed up on the part. How would I make the frame act like a screen gui?

What do you mean by making the frame work like a Screen Gui? Like for it to have buttons?

I want the fly button to be on a screen gui so it would be easier for the player to switch from fly mode
to car mode.

Okay. I’m confused on what your asking. Do you want a Gui like on a physical part or just on the player’s screen?

I want the gui on the players screen.

Okay, just make a normal Gui Button in a ScreenGui and then use RemoteEvents to communicate from the client to the server.

So I’m trying to make the screen gui not be in the startergui. I want it to start in the car. And once a player is found in the occupant property of the vehicle seat, the gui goes to the players playergui. The problem is that I can’t find out how to make the vehicle script and gui script communicate.

Use a RemoteEvent

I want the remote event to be in the car. I don’t know how to get the remote event on the local script once it transfers.

Ok. To make the Gui appear when a player sits down you could do something like this:

local Seat = game:GetService("Workspace").Seat5 -- change this to your seat.
local Gui = game:GetService("Workspace").GUI -- change this to your Gui

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
if Player then
		local Character = Player.Character 
		if Character then
			local GuiCloned = Gui:Clone()
			GuiCloned.Parent = Player.PlayerGui
			local Connection 
			Connection = Character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Sit"):Connect(function()
				if Character:WaitForChild("Humanoid").Sit == false then
					GuiCloned:Destroy()
					Connection:Disconnect()
				end
			end)
		end
	end
end
end)

Okay thats done. All I need now is to get the remote event thats parented towards the car into the local script which is what I’m struggling with.

Just do workspace.CarModel.RemoteEvent to reference it

And since it is on the client, make sure to use :WaitForChild()

Is there a better way in getting that remote event? Since the car can respawn, that means that the car can be destroyed. This will cause the script to error.