local Y={TireWearOn=true;FWearSpeed=.4;FTargetFriction=.7,FMinFriction=.1;RWearSpeed=.4,RTargetFriction=.7;RMinFriction=.1;TCSOffRatio=.33333333333333;WheelLockRatio=.5,WheelspinRatio=.90909090909091;FFrictionWeight=1,RFrictionWeight=1;FLgcyFrWeight=10;RLgcyFrWeight=10;FElasticity=.5;RElasticity=.5;FLgcyElasticity=0,RLgcyElasticity=0,FElastWeight=1,RElastWeight=1;FLgcyElWeight=10;RLgcyElWeight=10;RegenSpeed=3.6}local i=script.Parent.Parent.Car.Value local U=require(i["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local D=script.Parent.Parent:WaitForChild("\086\097\108\117\101\115")local I=U.FWheelDensity local k=U.RWheelDensity local q=Y.FFrictionWeight local d=Y.RFrictionWeight local b=Y.FElasticity local f=Y.RElasticity local t=Y.FElastWeight local W=Y.RElastWeight if not workspace:PGSIsEnabled()then I=U.FWLgcyDensity k=U.RWLgcyDensity q=Y.FLgcyFrWeight d=Y.FLgcyFrWeight b=Y.FLgcyElasticity f=Y.RLgcyElasticity t=Y.FLgcyElWeight W=Y.RLgcyElWeight end local V={}for i,D in pairs(i.Wheels:GetChildren())do local T={}T.wheel=D local M T.x=0 if D.Name=="\070\076"or D.Name=="\070\082"or D.Name=="\070"then M=(12-math.abs(U.FCamber))/15 T.x=I T.BaseHeat=Y.FTargetFriction-Y.FMinFriction T.WearSpeed=Y.FWearSpeed T.fWeight=q T.elast=b T.eWeight=t else M=(12-math.abs(U.RCamber))/15 T.x=k T.BaseHeat=Y.RTargetFriction-Y.RMinFriction T.WearSpeed=Y.RWearSpeed T.fWeight=d T.elast=f T.eWeight=W end T.Heat=T.BaseHeat T.stress=0 table.insert(V,T)end i.DriveSeat.ChildRemoved:connect(function(Y)if Y.Name=="\083\101\097\116\087\101\108\100"then local Y=i:FindFirstChild("\087\101\097\114\068\097\116\097")if i:FindFirstChild("\087\101\097\114\068\097\116\097")==nil then Y=script.Parent.WearData:Clone()Y.Parent=i end for i,U in pairs(V)do Y[U.wheel.Name].Value=U.Heat end Y.STime.Value=tick()end end)while wait()do for I,k in pairs(V)do local q=i.DriveSeat.Velocity.Magnitude local d=k.wheel.RotVelocity.Magnitude local b=0 local f=.000126 local t=(q/1.298)*(2.6/k.wheel.Size.Y)local W=math.abs(d-t)if Y.TireWearOn then if q<4 then k.Heat=math.min(k.Heat+Y.RegenSpeed/10000,k.BaseHeat)elseif W>1 then k.Heat=k.Heat-((W*f)*k.WearSpeed)/28 elseif k.Heat>=k.BaseHeat then k.Heat=k.BaseHeat end end if k.wheel.Name=="\070\076"or k.wheel.Name=="\070\082"or k.wheel.Name=="\070"then b=Y.FMinFriction+k.Heat f=(f-.0001188*D.Brake.Value)*(1-math.abs(D.SteerC.Value))+1.26e-06*math.abs(D.SteerC.Value)else b=Y.RMinFriction+k.Heat end if math.ceil(((d/.774)/q)*100)<8 then k.wheel.CustomPhysicalProperties=PhysicalProperties.new(k.x,b*Y.WheelLockRatio,k.elast,k.fWeight,k.eWeight)k.Heat=math.max(k.Heat,0)elseif U.TCSEnabled and(D.TCS.Value==false and math.ceil(((d/.774)/q)*100)>80)then k.wheel.CustomPhysicalProperties=PhysicalProperties.new(k.x,b*Y.TCSOffRatio,k.elast,k.fWeight,k.eWeight)k.Heat=math.max(k.Heat,0)elseif math.ceil(((d/.774)/q)*100)>130 then k.wheel.CustomPhysicalProperties=PhysicalProperties.new(k.x,b*Y.WheelspinRatio,k.elast,k.fWeight,k.eWeight)k.Heat=math.max(k.Heat,0)else k.wheel.CustomPhysicalProperties=PhysicalProperties.new(k.x,b,k.elast,k.fWeight,k.eWeight)k.Heat=math.min(k.Heat,k.BaseHeat)end local V=math.abs((((W+t)/.774)*.774-t)/15)if V>.05 and V>k.stress then k.stress=math.min(k.stress+.03,1)else k.stress=math.max(k.stress-.03,V)end local T=script.Parent.Tires[k.wheel.Name]T.First.Second.Image.ImageColor3=Color3.new(math.min(k.stress*2,1),1-k.stress,0)T.First.Position=UDim2.new(0,0,1-k.Heat/k.BaseHeat,0)T.First.Second.Position=UDim2.new(0,0,k.Heat/k.BaseHeat,0)end end
-- Decompiled with Visenya | https://targaryentech.com
local _WHEELTUNE = {
	TireWearOn = true,
	FWearSpeed = 0.4,
	FTargetFriction = 0.7,
	FMinFriction = 0.1,
	RWearSpeed = 0.4,
	RTargetFriction = 0.7,
	RMinFriction = 0.1,
	TCSOffRatio = 0.3333333333333333,
	WheelLockRatio = 0.5,
	WheelspinRatio = 0.9090909090909091,
	FFrictionWeight = 1,
	RFrictionWeight = 1,
	FLgcyFrWeight = 10,
	RLgcyFrWeight = 10,
	FElasticity = 0.5,
	RElasticity = 0.5,
	FLgcyElasticity = 0,
	RLgcyElasticity = 0,
	FElastWeight = 1,
	RElastWeight = 1,
	FLgcyElWeight = 10,
	RLgcyElWeight = 10,
	RegenSpeed = 3.6,
}
local car = script.Parent.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local cValues = script.Parent.Parent:WaitForChild("Values")
local fDensity = _Tune.FWheelDensity
local rDensity = _Tune.RWheelDensity
local fFwght = _WHEELTUNE.FFrictionWeight
local rFwght = _WHEELTUNE.RFrictionWeight
local fElast = _WHEELTUNE.FElasticity
local rElast = _WHEELTUNE.RElasticity
local fEwght = _WHEELTUNE.FElastWeight
local rEwght = _WHEELTUNE.RElastWeight
if not workspace:PGSIsEnabled() then
	fDensity = _Tune.FWLgcyDensity
	rDensity = _Tune.RWLgcyDensity
	fFwght = _WHEELTUNE.FLgcyFrWeight
	rFwght = _WHEELTUNE.FLgcyFrWeight
	fElast = _WHEELTUNE.FLgcyElasticity
	rElast = _WHEELTUNE.RLgcyElasticity
	fEwght = _WHEELTUNE.FLgcyElWeight
	rEwght = _WHEELTUNE.RLgcyElWeight
end
local Wheels = {}
for i, v in pairs(car.Wheels:GetChildren()) do
	local w = {}
	w.wheel = v
	local ca
	w.x = 0
	if v.Name == "FL" or v.Name == "FR" or v.Name == "F" then
		ca = (12 - math.abs(_Tune.FCamber)) / 15
		w.x = fDensity
		w.BaseHeat = _WHEELTUNE.FTargetFriction - _WHEELTUNE.FMinFriction
		w.WearSpeed = _WHEELTUNE.FWearSpeed
		w.fWeight = fFwght
		w.elast = fElast
		w.eWeight = fEwght
	else
		ca = (12 - math.abs(_Tune.RCamber)) / 15
		w.x = rDensity
		w.BaseHeat = _WHEELTUNE.RTargetFriction - _WHEELTUNE.RMinFriction
		w.WearSpeed = _WHEELTUNE.RWearSpeed
		w.fWeight = rFwght
		w.elast = rElast
		w.eWeight = rEwght
	end
	w.Heat = w.BaseHeat
	w.stress = 0
	table.insert(Wheels, w)
end
car.DriveSeat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		local wD = car:FindFirstChild("WearData")
		if car:FindFirstChild("WearData") == nil then
			wD = script.Parent.WearData:Clone()
			wD.Parent = car
		end
		for i, v in pairs(Wheels) do
			wD[v.wheel.Name].Value = v.Heat
		end
		wD.STime.Value = tick()
	end
end)
while wait() do
	for i, v in pairs(Wheels) do
		local speed = car.DriveSeat.Velocity.Magnitude
		local wheel = v.wheel.RotVelocity.Magnitude
		local z = 0
		local deg = 1.26E-4
		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
				v.Heat = math.min(v.Heat + _WHEELTUNE.RegenSpeed / 10000, v.BaseHeat)
			elseif wdif > 1 then
				v.Heat = v.Heat - wdif * deg * v.WearSpeed / 28
			elseif v.Heat >= v.BaseHeat then
				v.Heat = v.BaseHeat
			end
		end
		if v.wheel.Name == "FL" or v.wheel.Name == "FR" or v.wheel.Name == "F" then
			z = _WHEELTUNE.FMinFriction + v.Heat
			deg = (deg - 1.188E-4 * cValues.Brake.Value) * (1 - math.abs(cValues.SteerC.Value))
				+ 1.26E-6 * math.abs(cValues.SteerC.Value)
		else
			z = _WHEELTUNE.RMinFriction + v.Heat
		end
		if math.ceil(wheel / 0.774 / speed * 100) < 8 then
			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
			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
			v.wheel.CustomPhysicalProperties =
				PhysicalProperties.new(v.x, z * _WHEELTUNE.WheelspinRatio, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.max(v.Heat, 0)
		else
			v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x, z, v.elast, v.fWeight, v.eWeight)
			v.Heat = math.min(v.Heat, v.BaseHeat)
		end
		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
