So this script is supposed to make a vehicle's Parent be your character, and if you die, it will break the vehicle and remove it.
The script makes you the parent of the vehicle, but it won't break or get removed after you die. Can someone please help me?
Here's the script:
function onDie() human = nil script.Parent.Parent:BreakJoints() wait(3) script.Parent.Parent:remove() end function Child(c) if c.Name == "SeatWeld" and c.Part1.Name == "Torso" then human = c.Part1.Parent script.Parent.Parent.Parent = human human.Humanoid.Died:connect(onDie) end end function noChild() human = nil script.Parent.Parent.Parent = game.Workspace end script.Parent.ChildAdded:connect(Child) script.Parent.ChildRemoved:connect(noChild)
As per a comment above, you could use a for loop to remove welds instead of using the BreakJoints() method.
Also, PLEASE don't use the Remove() method. Instances that are removed rather than destroyed don't get added to the garbage collection list, and this can affect gameplay.
Example:
local car = script.Parent local function onDeath() human = nil local parts = car:GetChildren() for i = 1, #parts do if parts[i]:IsA("Weld") then parts[i]:Destroy() end end car:Destroy() end local function child(c) if c.Name == "SeatWeld" and c.Part1.Name == "Torso" then human = c.Part1.Parent script.Parent.Parent.Parent = human human.Humanoid.Died:connect(onDeath) end end local function noChild() human = nil script.Parent.Parent.Parent = game.Workspace end
Break the joints of the car model as well.