script.Parent:Destroy() not working

**script.Parent:Destroy() is not working in a script I made for cars on a highway.

This is the script that is inside of the car (Serverside not local)

local carspawns = script.Parent.Parent.Parent.Roads:WaitForChild("CarSpawns")
local car = script.Parent
local endvalue = car:WaitForChild("end")
local driving = car:WaitForChild("driving")
driving:GetPropertyChangedSignal("Value"):Connect(function()
	if driving.Value == true then
		for i = 0, 5, 0.001 do
			car.CFrame = car.CFrame:Lerp(carspawns["Endpos"..endvalue.Value].CFrame, i)
			wait()
		end
		script.Parent:Destroy()
	end
end)

All they do is pile on instead of deleting themselves as shown in the photovisual representation below:
https://gyazo.com/370f7a84f41beb5fc1695934d7a9937a

Is there anything I have to change for them to be deleted? I have tried making a part that destroys whatever touches it at the end of the highway, but that did not work either.

3 Likes

Put print in the script.Parent:Destroy() Line

4 Likes

I put print before and after the destroy line but it had no output

1 Like

Is the for loop working?This text will be blurred

2 Likes

The for loop works because it moves the car from point 1 to point 2 on the road using a lerp loop, and there are not any errors

1 Like

The loop does end right?This text will be blurred

1 Like

Could you show your explorer? (30 :expressionless: )

1 Like

the loop probably neverends?
add a print after

1 Like

Screenshot_4212

That’s what I’m thinking too :I

I just changed the increment value to a higher number. The loop ends and the parent is destroyed but now the lerp looks wicked, and the parent takes forever to get destroyed

What’s your main goal?

I actually just found a way to get the cars to have a good looking lerp with this:

if i >= 0.1 then
	script.Parent:Destroy()
end

However I am getting this error every time now:

Maybe cause you are destroying it even if it has already been destroyed

I only have a single destroy function in the script

Is it being destroyed :IThis text will be blurred

Maybe it goes to the void? It shouldn’t be nil.

The parent of car is script.Parent and driving is a child to car. How can this function ever return anything at all when it destroys itself internally here:

script.Parent:Destroy()