Issue with vehicle chassis configure script

Backstory:
I was writing a script to configure a vehicle chassis system using cylindrical constraints and springs. It was closely following something like this: How to Rig a Car and I am assuming its a pretty simple fix, its just been a while since I’ve done some development on ROBLOX.

Script:

-- // Written by apoaddda for Nourity Corporation
local function Weld(Part0 : Part, Part1 : Part)
	local weld = Instance.new("WeldConstraint", Part0)
	weld.Part0 = Part0
	weld.Part1 = Part1
end

-- // Weld Wheels together:
for i, model in pairs(script.Parent.Parent.Main.Wheels:GetChildren()) do
	if model:IsA("Model") then
		if model.Wheel:IsA("BasePart") then
			-- // Single Part
			Weld(model.Wheel, model.PhysicalWheel)
			model.Wheel.CanCollide = false
		else
			for i, v in pairs(model.Wheel:GetDescendants()) do
				if v:IsA("BasePart") then
					Weld(v, model.PhysicalWheel)
					v.CanCollide = false
				end
			end
		end
	end
end

-- // Weld Body to platform:
local platform = script.Parent.Parent.Chassis.Platform

for i, part in pairs(script.Parent.Parent.Main.Body:GetDescendants()) do
	if part:IsA("BasePart") then
		Weld(part, platform)
	end	
end

-- // Weld Mass to platform:
local Mass = script.Parent.Parent.Chassis.Mass

Weld(Mass, platform)

-- // Check all parts are massless:
for i, v in pairs(script.Parent.Parent:GetDescendants()) do
	if v:IsA("BasePart") then
		v.Massless = true
	end
end

-- // Make sure mass part has mass
Mass.Massless = false

-- // Set Can Collide on parts of chassis to false:
Mass.CanCollide = false
platform.CanCollide = false

-- // Set Collision Groups
local PhysicsService = game:GetService("PhysicsService")

-- // Set Body parts
for i, v in pairs(script.Parent.Parent.Main.Body:GetDescendants()) do
	if v:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(v, "CarBody")
	end
end

-- // Set Wheel
for i, wheel in pairs(script.Parent.Parent.Main.Wheels:GetChildren()) do
	PhysicsService:SetPartCollisionGroup(wheel.PhysicalWheel, "CarWheels")
end

-- // Contrainst:
platform.Anchored = true
for i, wheel in pairs(script.Parent.Parent.Main.Wheels:GetChildren()) do
	-- // CylindricalConstraint
	local Attachment0 = Instance.new("Attachment")
	local Attachment1 = Instance.new("Attachment")
	
	local CylindricalConstraint = Instance.new("CylindricalConstraint")
	CylindricalConstraint.Attachment0 = Attachment0
	CylindricalConstraint.Attachment1 = Attachment1
	
	-- // Springs:
	local Spring = Instance.new("SpringConstraint")
	Spring.Attachment0 = Attachment0
	Spring.Attachment1 = Attachment1
	
	-- // Put everything into position
	Attachment0.WorldPosition = Vector3.new(
		Attachment1.WorldPosition.X,
		Attachment0.WorldPosition.Y,
		Attachment1.WorldPosition.Z
	)
	
	-- Name prefix all:
	local NamePrefix = string.sub(wheel.Name, -2, #wheel.Name)
	CylindricalConstraint.Name = "Cylindrical" .. NamePrefix
	Attachment0.Name = "Attachment" .. NamePrefix
	Spring.Name = "Spring" .. NamePrefix
	
	-- // Set Orientation:
	if string.sub(NamePrefix, -1, #NamePrefix) == "R" then
		Attachment1.Orientation = Vector3.new(
			90, -- -90?
			-180,
			0
		)
		CylindricalConstraint.InclinationAngle = 90
	elseif string.sub(NamePrefix, -1, #NamePrefix) == "L" then
		Attachment1.Orientation = Vector3.new(
			90,
			-180,
			0
		)
		CylindricalConstraint.InclinationAngle = -90
	end
	
	-- // Set spring:
	Spring.Damping = 500
	Spring.Stiffness = 10000
	Spring.Visible = false
	
	-- // Parenting
	Attachment0.Parent = platform
	Attachment1.Parent = wheel.PhysicalWheel
	CylindricalConstraint.Parent = platform
	Spring.Parent = platform
end

wait(10)
platform.Anchored = false

And a video showing the bug:

Any help would be appreciated, spent a while looking for similar topics but I couldn’t find any. Probably something simple that I have missed/overlooked.

1 Like