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:
01 | function onDie() |
02 | human = nil |
03 | script.Parent.Parent:BreakJoints() |
04 | wait( 3 ) |
05 | script.Parent.Parent:remove() |
06 | end |
07 |
08 | function Child(c) |
09 | if c.Name = = "SeatWeld" and c.Part 1. Name = = "Torso" then |
10 | human = c.Part 1. Parent |
11 | script.Parent.Parent.Parent = human |
12 | human.Humanoid.Died:connect(onDie) |
13 | end |
14 | end |
15 |
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:
01 | local car = script.Parent |
02 |
03 | local function onDeath() |
04 | human = nil |
05 | local parts = car:GetChildren() |
06 | for i = 1 , #parts do |
07 | if parts [ i ] :IsA( "Weld" ) then |
08 | parts [ i ] :Destroy() |
09 | end |
10 | end |
11 | car:Destroy() |
12 | end |
13 |
14 | local function child(c) |
15 | if c.Name = = "SeatWeld" and c.Part 1. Name = = "Torso" then |
Break the joints of the car model as well.