How do i make a gui that popups when player is seated on vehicle seat?

I need help with making a gui popup when sitting in a custom made car, and then how can I control the car by clicking buttons on the gui, when there are multiple copies of the same car. Thank you for help!

1 Like

Simple PilotSeat:GetPropertyChanged('Occupant') will fire whenever an occupant sits or gets off a seat. Then you just have to check whether someone is still on or not.

local vehicle = script.Parent
local pilotSeat = vehicle.PilotSeat

local oldOccupant = pilotSeat.Occupant
pilotSeat:GetPropertyChanged('Occupant'):Connect(function()
  local occupant = pilotSeat.Occupant -- occupant is the humanoid of whatever is sat
  if occupant then -- if there is someone sitting
    local player = game.Players:GetPlayerFromCharacter(occupant.Parent) --get player
    if player then -- if it is a player character
      --add/enable the gui to the player
    end
    oldOccupant = occupant
  else -- if there is noone sitting
    local player = game.Players:GetPlayerFromCharacter(oldOccupant.Parent)
    if player then
      --remove/disable the gui to the player
    end 
    oldOccupant = nil
  end
end)
1 Like

I’ve tried it, and it’s not working :/, maybe I did something wrong?

local pilotSeat = script.Parent
local UI = script.Parent.Parent.Parent.CarGui -- this is a gui which is in the car

local oldOccupant = pilotSeat.Occupant
pilotSeat:GetPropertyChanged('Occupant'):Connect(function()
	local occupant = pilotSeat.Occupant -- occupant is the humanoid of whatever is sat
	if occupant then -- if there is someone sitting
		local player = game.Players:GetPlayerFromCharacter(occupant.Parent) --get player
		if player then -- if it is a player character
			local UIclone = UI:Clone()
			UIclone.Parent = player.PlayerGui
		end
		oldOccupant = occupant
	else -- if there is noone sitting
		local player = game.Players:GetPlayerFromCharacter(oldOccupant.Parent)
		if player then
			local gui = player:FindFirstChild("CarGui")
			gui:Destroy()
		end 
		oldOccupant = nil
	end
end)

Do you have any more ideas maybe?

I think hes missing Signal. If im not mistaken, its supposed to be GetPropertyChangedSignal

Link to documentation

Alright, I’ll try it, maybe it will work.