(continued from title) it gives them a GUI, then when they get out, it removes that GUI?
I know that the title shouldn't have a question mark, but I'm supposed to have one in there.
Here's what I got (all I have is the GUI giver):
--ScrewGuests local sp = script.Parent; function T(P) sp.Parent.Parent = P.Parent local plr = game:GetService('Players'):FindFirstChild(sp.Parent.Name) local hud = plr.PlayerGui:FindFirstChild("MphKphFlipGui") if hud == nil then script.MphKphFlipGui:Clone().Parent = plr.PlayerGui end end sp.Touched:connect(T)
The setup of the VehicleSeat is: VehicleSeat (VehicleSeat) -> GiveGui (Script) -> MphKphFlipGui (ScreenGui)
** - Put the Script inside a Seat. - Remove the GUI already inside the Script (It's just an example). - Put your own GUI inside the script. - Re-name the GUI to "GUI" (Without the quotation marks " ")**
Players = Game:GetService("Players") Workspace = Game:GetService("Workspace") Seat = script.Parent GUI = script.GUI Active = false Player = nil NewGui = nil Seat.ChildAdded:connect(function(Child) if Active == false then if Child.Name == "SeatWeld" then Active = true Player = Players:GetPlayerFromCharacter(Child.Part1.Parent) if Player ~= nil then PlayerGui = Player:FindFirstChild("PlayerGui") if PlayerGui ~= nil then NewGui = GUI:Clone() NewGui.Parent = PlayerGui end end end end end) Seat.ChildRemoved:connect(function(child) if child.Name == "SeatWeld" then if Active == true then Active = false pcall(function() NewGui:Destroy() end) Player = nil NewGui = nil end end end)
For the model go:
The easiest way I find to do this is to use the ChildAdded and ChildRemoved events. When someone sits in a seat it creates a seat weld between the character and seat, so you can very simply check when someone sits in a seat and who it was as well.
local driver -- This will hold a value for who sat in the seat local seat = script.Parent -- Location of the seat local gui = game.ServerStorage.ScreenGui -- Location of gui seat.ChildAdded:connect(function(added) if added.Name == "SeatWeld" then driver = seat.SeatWeld.Part1.Parent gui:Clone().Parent = game.Players:GetPlayerFromCharacter(driver).PlayerGui end end) seat.ChildRemoved:connect(function(removed) if removed.Name == "SeatWeld" then game.Players:GetPlayerFromCharacter(driver).PlayerGui:WaitForChild(gui.Name):Destroy() end end)