Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

Why is this Vehicle Script not Working?

Asked by 10 years ago

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:

01function onDie()
02    human = nil
03    script.Parent.Parent:BreakJoints()
04    wait(3)
05    script.Parent.Parent:remove()
06end
07 
08function Child(c)
09    if c.Name == "SeatWeld" and c.Part1.Name == "Torso" then
10        human = c.Part1.Parent
11        script.Parent.Parent.Parent = human
12        human.Humanoid.Died:connect(onDie)
13    end
14end
15 
View all 22 lines...

2 answers

Log in to vote
1
Answered by 10 years ago

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:

01local car = script.Parent
02 
03local 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()
12end
13 
14local function child(c)
15    if c.Name == "SeatWeld" and c.Part1.Name == "Torso" then
View all 25 lines...
0
Is a local script needed for this to work? CoolJohnnyboy 121 — 10y
0
No, it can be used in a normal script :) DevJackB 55 — 10y
Ad
Log in to vote
0
Answered by
Mr_Octree 101
10 years ago

Break the joints of the car model as well.

0
That's what script.Parent.Parent is, and it's not working. CoolJohnnyboy 121 — 10y
0
Maybe the vehicle is welded together. Why not just destroy the whole car model? The BreakJoints() method of destroying cars is a bit outdated and messier. Mr_Octree 101 — 10y
0
The BreakJoints() thing is for the sake of having it look decent. After is breaks, it gets removed. CoolJohnnyboy 121 — 10y
0
You could try using a for loop to remove any welds within the parts of the vehicle. Mr_Octree 101 — 10y
0
The vehicle didn't become a child of the player. Weird thing is, the regen button I had created a new vehicle, which it normally wouldn't do because of this script. CoolJohnnyboy 121 — 10y

Answer this question