I recently created a script, this script forces the vehicle to place a script inside of the player Gui upon getting inside of the vehicle. However, it is not working and is now printing out any errors whats so ever. Does anyone have any solution to this?
Script
-- [[ LOCALS ]] --
local Configuration = {
["Vehicle_Seat"] = script.Parent,
["Vehicle_Func"] = script.Parent.VehicleHandler
}
-- [[ FUNCTION ]] --
function Vehicle_Seat_Connect(Character)
if Character.Name == "SeatWeld" then
local Character_Data = {
["Path"] = Character.Part1:FindFirstChild("Humanoid")
}
if Character_Data.Path ~= nil then
Configuration.Vehicle_Seat.Parent.Name = Character.Parent.Name.."'s Car"
local Handler = Configuration.Vehicle_Func:Clone()
Handler.Parent = game:GetService("Players"):FindFirstChild(Character.Parent.Name).PlayerGui
Handler.Name = Configuration.Vehicle_Seat.Parent.Name
wait()
Handler.Enabled = true
end;
end;
end;
function Vehicle_Seat_Disconnect(Character)
if Character.Name == "SeatWeld" then
local Character_Data = {
["Path"] = Character.Part1:FindFirstChild("Humanoid")
}
if Character_Data.Path ~= nil then
local Player = game:GetService("Players")[Character.Parent.Name]
local Handler = Player:FindFirstChild(Configuration.Vehicle_Seat.Parent.Name)
Handler.Enabled = false
wait()
Handler:Destroy()
end;
end;
end;
Configuration.Vehicle_Seat.ChildAdded:Connect(Vehicle_Seat_Connect)
Configuration.Vehicle_Seat.ChildRemoved:Connect(Vehicle_Seat_Disconnect)
warn("VehicleHandler: Setup complete")
Consider listening for changes upon Seat.Occupant, this will equal the Humanoid of the current user of the seat, it’s a more efficient way of detecting if a player has sat or got up from the seat
local Players = game:GetService("Players")
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local human = Seat.Occupant
local p = if human then Players:GetPlayerFromCharacter(human) else nil
if p then
GiveGui(p)
end
end)
You’ll need to refactor this a bit to also detect when a player gets up, though it shouldn’t be too hard