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