while wait()do RegenSpeed=car.DriveSeat.Speed.Value FWearSpeed=car.DriveSeat.TireStats.Fwear.Value FTargetFriction=car.DriveSeat.TireStats.Ffriction.Value RWearSpeed=car.DriveSeat.TireStats.Rwear.Value RTargetFriction=car.DriveSeat.TireStats.Rfriction.Value for b,y in pairs(Wheels)do local V=car.DriveSeat.Velocity.Magnitude local S=y.wheel.RotVelocity.Magnitude local X=0 local U=.000126 local G=(V/1.298)*(2.6/y.wheel.Size.Y)local L=math.abs(S-G)if _WHEELTUNE.TireWearOn then if V<4 then y.Heat=math.min(y.Heat+car.DriveSeat.Speed.Value/10000,y.BaseHeat)else if L>1 then y.Heat=y.Heat-((L*U)*y.WearSpeed)/28 elseif y.Heat>=y.BaseHeat then y.Heat=y.BaseHeat end end end if y.wheel.Name=="\070\076"or y.wheel.Name=="\070\082"or y.wheel.Name=="\070"then X=_WHEELTUNE.FMinFriction+y.Heat U=(U-.0001188*cValues.Brake.Value)*(1-math.abs(cValues.SteerC.Value))+1.26e-06*math.abs(cValues.SteerC.Value)else X=_WHEELTUNE.RMinFriction+y.Heat end if math.ceil(((S/.774)/V)*100)<8 then y.wheel.CustomPhysicalProperties=PhysicalProperties.new(y.x,X*_WHEELTUNE.WheelLockRatio,y.elast,y.fWeight,y.eWeight)y.Heat=math.max(y.Heat,0)elseif _Tune.TCSEnabled and(cValues.TCS.Value==false and math.ceil(((S/.774)/V)*100)>80)then y.wheel.CustomPhysicalProperties=PhysicalProperties.new(y.x,X*_WHEELTUNE.TCSOffRatio,y.elast,y.fWeight,y.eWeight)y.Heat=math.max(y.Heat,0)elseif math.ceil(((S/.774)/V)*100)>130 then y.wheel.CustomPhysicalProperties=PhysicalProperties.new(y.x,X*_WHEELTUNE.WheelspinRatio,y.elast,y.fWeight,y.eWeight)y.Heat=math.max(y.Heat,0)else y.wheel.CustomPhysicalProperties=PhysicalProperties.new(y.x,X,y.elast,y.fWeight,y.eWeight)y.Heat=math.min(y.Heat,y.BaseHeat)end local D=math.abs((((L+G)/.774)*.774-G)/15)if D>.05 and D>y.stress then y.stress=math.min(y.stress+.03,1)else y.stress=math.max(y.stress-.03,D)end local g=script.Parent.Tires[y.wheel.Name]g.First.Second.Image.ImageColor3=Color3.new(math.min(y.stress*2,1),1-y.stress,0)g.First.Position=UDim2.new(0,0,1-y.Heat/y.BaseHeat,0)g.First.Second.Position=UDim2.new(0,0,y.Heat/y.BaseHeat,0)end end
--Runtime Loop
while wait() do
	RegenSpeed = car.DriveSeat.Speed.Value
	FWearSpeed = car.DriveSeat.TireStats.Fwear.Value
	FTargetFriction = car.DriveSeat.TireStats.Ffriction.Value
	RWearSpeed = car.DriveSeat.TireStats.Rwear.Value
	RTargetFriction = car.DriveSeat.TireStats.Rfriction.Value
	for i, v in pairs(Wheels) do
		--Vars
		local speed = car.DriveSeat.Velocity.Magnitude
		local wheel = v.wheel.RotVelocity.Magnitude
		local z = 0
		local deg = 0.000126
		--Tire Wear
		local cspeed = (speed / 1.298) * (2.6 / v.wheel.Size.Y)
		local wdif = math.abs(wheel - cspeed)
		if _WHEELTUNE.TireWearOn then
			if speed < 4 then
				--Wear Regen
				v.Heat = math.min(v.Heat + car.DriveSeat.Speed.Value / 10000, v.BaseHeat)
			else
				--Tire Wear
				if wdif > 1 then
					v.Heat = v.Heat - wdif * deg * v.WearSpeed / 28
				elseif v.Heat >= v.BaseHeat then
					v.Heat = v.BaseHeat
				end
			end
		end

		--Apply Friction
		if v.wheel.Name == "FL" or v.wheel.Name == "FR" or v.wheel.Name == "F" then
			z = _WHEELTUNE.FMinFriction + v.Heat
			deg = ((deg - 0.0001188 * cValues.Brake.Value) * (1 - math.abs(cValues.SteerC.Value)))
				+ 0.00000126 * math.abs(cValues.SteerC.Value)
		else
			z = _WHEELTUNE.RMinFriction + v.Heat
		end

		--Tire Slip
		if math.ceil((wheel / 0.774 / speed) * 100) < 8 then
			--Lock Slip
			v.wheel.CustomPhysicalProperties =
				PhysicalProperties.new(v.x, z * _WHEELTUNE.WheelLockRatio, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.max(v.Heat, 0)
		elseif _Tune.TCSEnabled and cValues.TCS.Value == false and math.ceil((wheel / 0.774 / speed) * 100) > 80 then
			--TCS Off
			v.wheel.CustomPhysicalProperties =
				PhysicalProperties.new(v.x, z * _WHEELTUNE.TCSOffRatio, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.max(v.Heat, 0)
		elseif math.ceil((wheel / 0.774 / speed) * 100) > 130 then
			--Wheelspin
			v.wheel.CustomPhysicalProperties =
				PhysicalProperties.new(v.x, z * _WHEELTUNE.WheelspinRatio, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.max(v.Heat, 0)
		else
			--No Slip
			v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x, z, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.min(v.Heat, v.BaseHeat)
		end

		--Update UI
		local vstress = math.abs(((((wdif + cspeed) / 0.774) * 0.774) - cspeed) / 15)
		if vstress > 0.05 and vstress > v.stress then
			v.stress = math.min(v.stress + 0.03, 1)
		else
			v.stress = math.max(v.stress - 0.03, vstress)
		end
		local UI = script.Parent.Tires[v.wheel.Name]
		UI.First.Second.Image.ImageColor3 = Color3.new(math.min((v.stress * 2), 1), 1 - v.stress, 0)
		UI.First.Position = UDim2.new(0, 0, 1 - v.Heat / v.BaseHeat, 0)
		UI.First.Second.Position = UDim2.new(0, 0, v.Heat / v.BaseHeat, 0)
	end
end
