local s=0 function getMass(d)for d,h in pairs(d:GetChildren())do if h:IsA("\066\097\115\101\080\097\114\116")and not h.Massless then s=s+h:GetMass()end getMass(h)end end getMass(car)if s<(_Tune.Weight/2.205)/8 then local d=Vector3.new()local h=Vector3.new()local F=0 local o=0 for s,A in pairs(Drive)do if A.Name=="\070\076"or A.Name=="\070\082"or A.Name=="\070"then d=d+A.CFrame.p F=F+1 else h=h+A.CFrame.p o=o+1 end end d=d/F h=h/o local A=h:Lerp(d,_Tune.WeightDist/100)local M=Instance.new("\080\097\114\116",car.Body)M.Name="\035\087\101\105\103\104\116"M.Anchored=true M.CanCollide=false M.BrickColor=BrickColor.new("\082\101\097\108\108\121 \098\108\097\099\107")M.TopSurface=Enum.SurfaceType.Smooth M.BottomSurface=Enum.SurfaceType.Smooth if _Tune.WBVisible then M.Transparency=.75 else M.Transparency=1 end M.Size=Vector3.new(_Tune.WeightBSize[1],_Tune.WeightBSize[2],_Tune.WeightBSize[3])local k=((_Tune.Weight/2.205-s/8)/((((M.Size.x*M.Size.y)*M.Size.z)*1000)/61024))/1000 M.CustomPhysicalProperties=PhysicalProperties.new(k,0,0,0,0)M.CFrame=((car.DriveSeat.CFrame-car.DriveSeat.Position)+A)*CFrame.new(0,_Tune.CGHeight,0)if M.CustomPhysicalProperties.Density>=2 then warn("\n\t \091\065\067\054\067 \086"..(_BuildVersion..("\093\058 \068\101\110\115\105\116\121 \116\111\111 \104\105\103\104 \102\111\114 \115\112\101\099\105\102\105\101\100 \118\111\108\117\109\101\046"..("\n\t \067\117\114\114\101\110\116 \068\101\110\115\105\116\121\058\t"..(math.ceil(k)..("\n\t \077\097\120 \068\101\110\115\105\116\121\058\t"..(math.ceil(M.CustomPhysicalProperties.Density).."\n\t \073\110\099\114\101\097\115\101 \119\101\105\103\104\116 \098\114\105\099\107 \115\105\122\101 \116\111 \099\111\109\112\101\110\115\097\116\101\046")))))))end else warn("\n\t \091\065\067\054\067 \086"..(_BuildVersion..("\093\058 \077\097\115\115 \116\111\111 \104\105\103\104 \102\111\114 \115\112\101\099\105\102\105\101\100 \119\101\105\103\104\116\046"..("\n\t    \084\097\114\103\101\116 \077\097\115\115\058\t"..(math.ceil((_Tune.Weight*2.205)*8)..("\n\t    \067\117\114\114\101\110\116 \077\097\115\115\058\t"..(math.ceil(s).."\n\t \082\101\100\117\099\101 \112\097\114\116 \115\105\122\101 \111\114 \097\120\108\101 \100\101\110\115\105\116\121 \116\111 \097\099\104\105\101\118\101 \100\101\115\105\114\101\100 \119\101\105\103\104\116\046")))))))end local d=Instance.new("\066\111\100\121\071\121\114\111",car.DriveSeat)d.Name="\070\108\105\112"d.D=0 d.MaxTorque=Vector3.new(0,0,0)d.P=0
--[[Vehicle Weight]]
--Determine Current Mass
local mass = 0

function getMass(p)
	for i, v in pairs(p:GetChildren()) do
		if v:IsA("BasePart") and not v.Massless then
			mass = mass + v:GetMass()
		end
		getMass(v)
	end
end
getMass(car)

--Apply Vehicle Weight
if mass < _Tune.Weight / 2.205 / 8 then
	--Calculate Weight Distribution
	local centerF = Vector3.new()
	local centerR = Vector3.new()
	local countF = 0
	local countR = 0

	for i, v in pairs(Drive) do
		if v.Name == "FL" or v.Name == "FR" or v.Name == "F" then
			centerF = centerF + v.CFrame.p
			countF = countF + 1
		else
			centerR = centerR + v.CFrame.p
			countR = countR + 1
		end
	end
	centerF = centerF / countF
	centerR = centerR / countR
	local center = centerR:Lerp(centerF, _Tune.WeightDist / 100)

	--Create Weight Brick
	local weightB = Instance.new("Part", car.Body)
	weightB.Name = "#Weight"
	weightB.Anchored = true
	weightB.CanCollide = false
	weightB.BrickColor = BrickColor.new("Really black")
	weightB.TopSurface = Enum.SurfaceType.Smooth
	weightB.BottomSurface = Enum.SurfaceType.Smooth
	if _Tune.WBVisible then
		weightB.Transparency = 0.75
	else
		weightB.Transparency = 1
	end

	weightB.Size = Vector3.new(_Tune.WeightBSize[1], _Tune.WeightBSize[2], _Tune.WeightBSize[3])
	local tdensity = (_Tune.Weight / 2.205 - mass / 8)
		/ (weightB.Size.x * weightB.Size.y * weightB.Size.z * 1000 / 61024)
		/ 1000
	weightB.CustomPhysicalProperties = PhysicalProperties.new(tdensity, 0, 0, 0, 0)
	--Real life mass in kg minus existing roblox mass converted to kg, divided by volume of the weight brick in cubic meters, divided by the density of water
	weightB.CFrame = (car.DriveSeat.CFrame - car.DriveSeat.Position + center) * CFrame.new(0, _Tune.CGHeight, 0)

	--Density Cap
	if weightB.CustomPhysicalProperties.Density >= 2 then
		warn(
			"\n\t [AC6C V"
				.. _BuildVersion
				.. "]: Density too high for specified volume."
				.. "\n\t Current Density:\t"
				.. math.ceil(tdensity)
				.. "\n\t Max Density:\t"
				.. math.ceil(weightB.CustomPhysicalProperties.Density)
				.. "\n\t Increase weight brick size to compensate."
		)
	end
else
	--Existing Weight Is Too Massive
	warn(
		"\n\t [AC6C V"
			.. _BuildVersion
			.. "]: Mass too high for specified weight."
			.. "\n\t    Target Mass:\t"
			.. math.ceil((_Tune.Weight * 2.205) * 8)
			.. "\n\t    Current Mass:\t"
			.. math.ceil(mass)
			.. "\n\t Reduce part size or axle density to achieve desired weight."
	)
end

local flipG = Instance.new("BodyGyro", car.DriveSeat)
flipG.Name = "Flip"
flipG.D = 0
flipG.MaxTorque = Vector3.new(0, 0, 0)
flipG.P = 0
