while wait()do for A,U in pairs(Wheels)do local l=car.DriveSeat.Velocity.Magnitude local d=U.wheel.RotVelocity.Magnitude local Y=0 local K=.000126 local h=(l/1.298)*(2.6/U.wheel.Size.Y)local H=math.abs(d-h)if _WHEELTUNE.TireWearOn then if l<4 then U.Heat=math.min(U.Heat+_WHEELTUNE.RegenSpeed/10000,U.BaseHeat)else if H>1 then U.Heat=U.Heat-((H*K)*U.WearSpeed)/28 elseif U.Heat>=U.BaseHeat then U.Heat=U.BaseHeat end end end if U.wheel.Name=="\070\076"or U.wheel.Name=="\070\082"or U.wheel.Name=="\070"then Y=_WHEELTUNE.FMinFriction+U.Heat K=(K-.0001188*cValues.Brake.Value)*(1-math.abs(cValues.SteerC.Value))+1.26e-06*math.abs(cValues.SteerC.Value)else Y=_WHEELTUNE.RMinFriction+U.Heat end if math.ceil(((d/.774)/l)*100)<8 then U.wheel.CustomPhysicalProperties=PhysicalProperties.new(U.x,Y*_WHEELTUNE.WheelLockRatio,U.elast,U.fWeight,U.eWeight)U.Heat=math.max(U.Heat,0)elseif _Tune.TCSEnabled and(cValues.TCS.Value==false and math.ceil(((d/.774)/l)*100)>80)then U.wheel.CustomPhysicalProperties=PhysicalProperties.new(U.x,Y*_WHEELTUNE.TCSOffRatio,U.elast,U.fWeight,U.eWeight)U.Heat=math.max(U.Heat,0)elseif math.ceil(((d/.774)/l)*100)>130 then U.wheel.CustomPhysicalProperties=PhysicalProperties.new(U.x,Y*_WHEELTUNE.WheelspinRatio,U.elast,U.fWeight,U.eWeight)U.Heat=math.max(U.Heat,0)else U.wheel.CustomPhysicalProperties=PhysicalProperties.new(U.x,Y,U.elast,U.fWeight,U.eWeight)U.Heat=math.min(U.Heat,U.BaseHeat)end local V=math.abs((((H+h)/.774)*.774-h)/15)if V>.05 and V>U.stress then U.stress=math.min(U.stress+.03,1)else U.stress=math.max(U.stress-.03,V)end script.Parent:WaitForChild("\084\105\114\101\115")local Z=script.Parent.Tires[U.wheel.Name]Z.First.Second.Image.ImageColor3=Color3.new(math.min(U.stress*2,1),1-U.stress,0)Z.First.Position=UDim2.new(0,0,1-U.Heat/U.BaseHeat,0)Z.First.Second.Position=UDim2.new(0,0,U.Heat/U.BaseHeat,0)end end

while wait() do
	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 + _WHEELTUNE.RegenSpeed/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
		script.Parent:WaitForChild("Tires")
		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
