--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)
