for y,c in pairs(script.Parent.Parent:GetChildren())do if string.find(c.Name,"\070\082")then FRtire=c.PhysicsTire elseif string.find(c.Name,"\070\076")then FLtire=c.PhysicsTire elseif string.find(c.Name,"\082\082")then RRtire=c.PhysicsTire elseif string.find(c.Name,"\082\076")then RLtire=c.PhysicsTire end end local y=(script.Parent.Parent.Base.Position-FRtire.Position).magnitude+.5 local c=(script.Parent.Parent.Rear.Position-RRtire.Position).magnitude+.5 function deleteCar()print("\068\101\108\101\116\105\110\103 \099\097\114 \102\108\105\110\103")script.Parent.Parent.Parent:Destroy()end thrust.Force=Vector3.new(0,0,0)seat.Changed:Connect(function()if not inLoop then inLoop=true repeat wait(.3)local T=seat.Velocity.Magnitude if T>90 and seat.Occupant~=nil then factor=(55/T)*factorMain elseif T>60 and(T<=90 and seat.Occupant~=nil)then factor=(51/T)*factorMain elseif T>30 and(T<=60 and seat.Occupant~=nil)then factor=(47/T)*factorMain elseif T>10 and(T<=30 and seat.Occupant~=nil)then factor=(40/T)*factorMain elseif T<10 and(T<=1 and seat.Occupant~=nil)then factor=.9*factorMain elseif T<30 and seat.Occupant==nil then factor=.5*factorMain end if T>maxSpeed+2 then factor=factorMain/2 end if seat.Throttle==-1 then factor=factor*-1 elseif seat.Throttle==1 then factor=factor/2 end thrust.Force=Vector3.new(0,0,(400*T)*factor)if(script.Parent.Parent.Base.Position-FRtire.Position).magnitude>y then wait(1)if(script.Parent.Parent.Base.Position-FRtire.Position).magnitude>y then deleteCar()end end if(script.Parent.Parent.Base.Position-FLtire.Position).magnitude>y then wait(1)if(script.Parent.Parent.Base.Position-FLtire.Position).magnitude>y then deleteCar()end end if(script.Parent.Parent.Rear.Position-RRtire.Position).magnitude>c then wait(1)if(script.Parent.Parent.Rear.Position-RRtire.Position).magnitude>c then deleteCar()end end if(script.Parent.Parent.Rear.Position-RLtire.Position).magnitude>c then wait(1)if(script.Parent.Parent.Rear.Position-RLtire.Position).magnitude>c then deleteCar()end end until T<1 inLoop=false end end)
--For tires:
for i, child in pairs(script.Parent.Parent:GetChildren()) do
	if string.find(child.Name, "FR") then
		FRtire = child.PhysicsTire
	elseif string.find(child.Name, "FL") then
		FLtire = child.PhysicsTire
	elseif string.find(child.Name, "RR") then
		RRtire = child.PhysicsTire
	elseif string.find(child.Name, "RL") then
		RLtire = child.PhysicsTire
	end
end
local frontDistance = (script.Parent.Parent.Base.Position - FRtire.Position).magnitude + 0.5
local rearDistance = (script.Parent.Parent.Rear.Position - RRtire.Position).magnitude + 0.5
function deleteCar()
	print("Deleting car fling")
	script.Parent.Parent.Parent:Destroy()
end

thrust.Force = Vector3.new(0, 0, 0)

seat.Changed:Connect(function()
	if not inLoop then
		inLoop = true
		repeat
			wait(0.3)
			local speed = seat.Velocity.Magnitude

			if speed > 90 and seat.Occupant ~= nil then
				factor = (55 / speed) * factorMain --
			elseif speed > 60 and speed <= 90 and seat.Occupant ~= nil then
				factor = (51 / speed) * factorMain --
			elseif speed > 30 and speed <= 60 and seat.Occupant ~= nil then
				factor = (47 / speed) * factorMain --
			elseif speed > 10 and speed <= 30 and seat.Occupant ~= nil then
				factor = (40 / speed) * factorMain --
			elseif speed < 10 and speed <= 1 and seat.Occupant ~= nil then
				factor = 0.9 * factorMain --
			elseif speed < 30 and seat.Occupant == nil then
				factor = 0.5 * factorMain --
			end

			if speed > maxSpeed + 2 then
				factor = factorMain / 2
			end

			if seat.Throttle == -1 then
				factor = factor * -1
			elseif seat.Throttle == 1 then
				factor = factor / 2
			end

			thrust.Force = Vector3.new(0, 0, (400 * speed * factor))
			--print (speed,thrust.Force)

			--For tires
			if (script.Parent.Parent.Base.Position - FRtire.Position).magnitude > frontDistance then
				wait(1)
				if (script.Parent.Parent.Base.Position - FRtire.Position).magnitude > frontDistance then
					deleteCar()
				end
			end
			if (script.Parent.Parent.Base.Position - FLtire.Position).magnitude > frontDistance then
				wait(1)
				if (script.Parent.Parent.Base.Position - FLtire.Position).magnitude > frontDistance then
					deleteCar()
				end
			end
			if (script.Parent.Parent.Rear.Position - RRtire.Position).magnitude > rearDistance then
				wait(1)
				if (script.Parent.Parent.Rear.Position - RRtire.Position).magnitude > rearDistance then
					deleteCar()
				end
			end
			if (script.Parent.Parent.Rear.Position - RLtire.Position).magnitude > rearDistance then
				wait(1)
				if (script.Parent.Parent.Rear.Position - RLtire.Position).magnitude > rearDistance then
					deleteCar()
				end
			end

		until speed < 1
		inLoop = false
	end
end)
