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