uv=script.Parent.CFrame.upVector local P=WeightDistribution local l=P/25 local r=(100-P)/25 local O=math.max(0,r-1)local v=math.min(l,1)local S=(FL.Position+FR.Position)*O local z=(RL.Position+RR.Position)*v local x=(O+v)*2 local A=Instance.new("\080\097\114\116")A.Parent=script.Parent.Parent A.CanCollide=false A.Position=script.Parent.Position A.CFrame=CFrame.new((S+z)/x)A.Position=A.Position+Vector3.new(.9,.9,.9)*script.Parent.CFrame.upVector A.Size=Vector3.new(3,2,4)A.Rotation=script.Parent.Rotation A.Name="\087\101\105\103\104\116"A.Anchored=true local U=Instance.new("\080\097\114\116")U.Anchored=true U.Parent=script.Parent.Parent U.CanCollide=false U.Position=script.Parent.Position U.Position=U.Position+Vector3.new(2,2,2)*script.Parent.CFrame.upVector U.Size=Vector3.new(1,.7,.7)*(EngineDisplacement/4000)+Vector3.new(2,1.4,1.4)U.Rotation=script.Parent.Rotation U.Name="\069\110\103\105\110\101"local k=Instance.new("\080\097\114\116")k.Anchored=true k.Parent=script.Parent.Parent k.CanCollide=false k.Position=script.Parent.Position k.Position=k.Position+Vector3.new(2.5,2.5,2.5)*script.Parent.CFrame.upVector k.Size=Vector3.new(2.5,2.5,7)k.Rotation=script.Parent.Rotation k.Name="\070\117\101\108\084\097\110\107"local B=Instance.new("\080\097\114\116")B.Anchored=true B.Parent=script.Parent.Parent B.CanCollide=false B.Position=script.Parent.Position B.Position=B.Position+Vector3.new(3,3,3)*script.Parent.CFrame.upVector B.Size=Vector3.new(2.7,2,2)*(AmountOfGears/7)B.Rotation=script.Parent.Rotation B.Name="\084\114\097\110\115\109\105\115\115\105\111\110"local s=Instance.new("\080\097\114\116")s.Anchored=true s.Parent=script.Parent.Parent s.CanCollide=false s.Position=script.Parent.Position s.Position=s.Position+Vector3.new(3.5,3.5,3.5)*script.Parent.CFrame.upVector s.Size=Vector3.new(2,2,2)s.Rotation=script.Parent.Rotation s.Name="\068\105\102\102\101\114\101\110\116\105\097\108"k.CFrame=CFrame.new((RL.Position+RR.Position)/2)k.CFrame=k.CFrame+Vector3.new(3,3,3)*lv if Drivetrain=="\082\087\068"then s.CFrame=CFrame.new((RL.Position+RR.Position)/2)elseif Drivetrain=="\070\087\068"then s.CFrame=CFrame.new((FL.Position+FR.Position)/2)U.Rotation=U.Rotation+Vector3.new(0,90,0)elseif Drivetrain=="\065\087\068"then s.CFrame=CFrame.new((RL.Position+RR.Position)/2)if TorqueSplit<51 then U.Rotation=U.Rotation+Vector3.new(0,90,0)end end if EngineLocation=="\070\114\111\110\116"then U.CFrame=CFrame.new((FL.Position+FR.Position)/2)U.CFrame=U.CFrame+Vector3.new(2,2,2)*lv U.CFrame=U.CFrame+Vector3.new(1,1,1)*uv B.CFrame=U.CFrame+Vector3.new(-1.5,-1.5,-1.5)*lv elseif EngineLocation=="\077\105\100"then U.CFrame=CFrame.new((RL.Position+RR.Position)/2)U.CFrame=U.CFrame+Vector3.new(2,2,2)*lv U.CFrame=U.CFrame+Vector3.new(1,1,1)*uv B.CFrame=U.CFrame+Vector3.new(1.5,1.5,1.5)*lv elseif EngineLocation=="\082\101\097\114"then U.CFrame=CFrame.new((RL.Position+RR.Position)/2)U.CFrame=U.CFrame+Vector3.new(-2,-2,-2)*lv U.CFrame=U.CFrame+Vector3.new(1,1,1)*uv B.CFrame=U.CFrame+Vector3.new(-1.5,-1.5,-1.5)*lv end rv=script.Parent.CFrame.rightVector
--Weight Setup--

uv = script.Parent.CFrame.upVector

local distribution = WeightDistribution --0-100%, how much of the weight is in the rear, 50 = 50%/50%

local DistA = (distribution / 25)
local DistB = ((100 - distribution) / 25)

local Dist1 = math.max(0, DistB - 1)
local Dist2 = math.min(DistA, 1)

local DistF = (FL.Position + FR.Position) * Dist1
local DistR = (RL.Position + RR.Position) * Dist2
local DistD = (Dist1 + Dist2) * 2

local weight = Instance.new("Part")
weight.Parent = script.Parent.Parent
weight.CanCollide = false
weight.Position = script.Parent.Position
weight.CFrame = CFrame.new((DistF + DistR) / DistD)
weight.Position = weight.Position + Vector3.new(0.9, 0.9, 0.9) * script.Parent.CFrame.upVector
weight.Size = Vector3.new(3, 2, 4)
weight.Rotation = script.Parent.Rotation
weight.Name = "Weight"
weight.Anchored = true

local engine = Instance.new("Part")
engine.Anchored = true
engine.Parent = script.Parent.Parent
engine.CanCollide = false
engine.Position = script.Parent.Position
engine.Position = engine.Position + Vector3.new(2, 2, 2) * script.Parent.CFrame.upVector
engine.Size = (Vector3.new(1, 0.7, 0.7) * (EngineDisplacement / 4000)) + Vector3.new(2, 1.4, 1.4)
engine.Rotation = script.Parent.Rotation
engine.Name = "Engine"

local fuel = Instance.new("Part")
fuel.Anchored = true
fuel.Parent = script.Parent.Parent
fuel.CanCollide = false
fuel.Position = script.Parent.Position
fuel.Position = fuel.Position + Vector3.new(2.5, 2.5, 2.5) * script.Parent.CFrame.upVector
fuel.Size = Vector3.new(2.5, 2.5, 7)
fuel.Rotation = script.Parent.Rotation
fuel.Name = "FuelTank"

local trans = Instance.new("Part")
trans.Anchored = true
trans.Parent = script.Parent.Parent
trans.CanCollide = false
trans.Position = script.Parent.Position
trans.Position = trans.Position + Vector3.new(3, 3, 3) * script.Parent.CFrame.upVector
trans.Size = Vector3.new(2.7, 2, 2) * (AmountOfGears / 7)
trans.Rotation = script.Parent.Rotation
trans.Name = "Transmission"

local diff = Instance.new("Part")
diff.Anchored = true
diff.Parent = script.Parent.Parent
diff.CanCollide = false
diff.Position = script.Parent.Position
diff.Position = diff.Position + Vector3.new(3.5, 3.5, 3.5) * script.Parent.CFrame.upVector
diff.Size = Vector3.new(2, 2, 2)
diff.Rotation = script.Parent.Rotation
diff.Name = "Differential"

fuel.CFrame = CFrame.new((RL.Position + RR.Position) / 2)
fuel.CFrame = fuel.CFrame + Vector3.new(3, 3, 3) * lv

if Drivetrain == "RWD" then
	diff.CFrame = CFrame.new((RL.Position + RR.Position) / 2)
elseif Drivetrain == "FWD" then
	diff.CFrame = CFrame.new((FL.Position + FR.Position) / 2)
	engine.Rotation = engine.Rotation + Vector3.new(0, 90, 0)
elseif Drivetrain == "AWD" then
	diff.CFrame = CFrame.new((RL.Position + RR.Position) / 2)

	if TorqueSplit < 51 then
		engine.Rotation = engine.Rotation + Vector3.new(0, 90, 0)
	end
end

if EngineLocation == "Front" then
	engine.CFrame = CFrame.new((FL.Position + FR.Position) / 2)
	engine.CFrame = engine.CFrame + Vector3.new(2, 2, 2) * lv
	engine.CFrame = engine.CFrame + Vector3.new(1, 1, 1) * uv
	trans.CFrame = engine.CFrame + Vector3.new(-1.5, -1.5, -1.5) * lv
elseif EngineLocation == "Mid" then
	engine.CFrame = CFrame.new((RL.Position + RR.Position) / 2)
	engine.CFrame = engine.CFrame + Vector3.new(2, 2, 2) * lv
	engine.CFrame = engine.CFrame + Vector3.new(1, 1, 1) * uv
	trans.CFrame = engine.CFrame + Vector3.new(1.5, 1.5, 1.5) * lv
elseif EngineLocation == "Rear" then
	engine.CFrame = CFrame.new((RL.Position + RR.Position) / 2)
	engine.CFrame = engine.CFrame + Vector3.new(-2, -2, -2) * lv
	engine.CFrame = engine.CFrame + Vector3.new(1, 1, 1) * uv
	trans.CFrame = engine.CFrame + Vector3.new(-1.5, -1.5, -1.5) * lv
end

rv = script.Parent.CFrame.rightVector
