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

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
