local function r(r)local H,o=Raycast.new(r.Position,r.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0))*stats.Height.Value)local S=(o-r.Position).magnitude local d=r:FindFirstChild("\087\104\101\101\108\087\101\108\100")d.C0=CFrame.new(0,-math.min(S,stats.Height.Value*.8)+d.Part1.Size.Y/2,0)local R=car.Chassis.CFrame:inverse()*r.CFrame local h=car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)if R.Z<0 then local r=1 if h.Z>0 then r=-1 end d.C0=d.C0*CFrame.Angles(0,(car.Chassis.RotVelocity.Y/2)*r,0)end if H and r.Velocity.magnitude>=5 then d.Part1.ParticleEmitter.Enabled=true else d.Part1.ParticleEmitter.Enabled=false end end car.DriveSeat.Changed:connect(function(r)if r=="\079\099\099\117\112\097\110\116"then if car.DriveSeat.Occupant then car.EngineBlock.Running.Pitch=1 car.EngineBlock.Running:Play()local r=game.Players:GetPlayerFromCharacter(car.DriveSeat.Occupant.Parent)if r then car.DriveSeat:SetNetworkOwner(r)local H=script.LocalCarScript:Clone()H.Parent=r.PlayerGui H.Car.Value=car H.Disabled=false end else car.EngineBlock.Running:Stop()end end end)
--local bodyPosition = Instance.new("BodyPosition", car.Chassis)
--bodyPosition.MaxForce = Vector3.new()
--local bodyGyro = Instance.new("BodyGyro", car.Chassis)
--bodyGyro.MaxTorque = Vector3.new()

local function UpdateThruster(thruster)
	-- Raycasting
	local hit, position =
		Raycast.new(thruster.Position, thruster.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value) --game.Workspace:FindPartOnRay(ray, car)
	local thrusterHeight = (position - thruster.Position).magnitude

	-- Wheel
	local wheelWeld = thruster:FindFirstChild("WheelWeld")
	wheelWeld.C0 = CFrame.new(0, -math.min(thrusterHeight, stats.Height.Value * 0.8) + (wheelWeld.Part1.Size.Y / 2), 0)
	-- Wheel turning
	local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
	local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
	if offset.Z < 0 then
		local direction = 1
		if speed.Z > 0 then
			direction = -1
		end
		wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
	end

	-- Particles
	if hit and thruster.Velocity.magnitude >= 5 then
		wheelWeld.Part1.ParticleEmitter.Enabled = true
	else
		wheelWeld.Part1.ParticleEmitter.Enabled = false
	end
end

car.DriveSeat.Changed:connect(function(property)
	if property == "Occupant" then
		if car.DriveSeat.Occupant then
			car.EngineBlock.Running.Pitch = 1
			car.EngineBlock.Running:Play()
			local player = game.Players:GetPlayerFromCharacter(car.DriveSeat.Occupant.Parent)
			if player then
				car.DriveSeat:SetNetworkOwner(player)
				local localCarScript = script.LocalCarScript:Clone()
				localCarScript.Parent = player.PlayerGui
				localCarScript.Car.Value = car
				localCarScript.Disabled = false
			end
		else
			car.EngineBlock.Running:Stop()
		end
	end
end)
