Collisions and CFrames

Hey so I have had some more issues with my chair lift.
I created a script to clone my carts / chairs from server storage (i know it’s not secure but who cares), however they all spawn at one point and collide causing this mess:

image

So, I am wondering could anyone show me how to create a script with a No-Collission constraint between the chairs however you still need to be able to sit in them, so it’s not as easy as turning of can collide.


Current script below in server script


local cartSpeed = game.Workspace.SkiPoleLine.Paths.Configuration:WaitForChild("Speed").Value
local speed = cartSpeed

for i, folder in ipairs(workspace.SkiPoleLine.Paths:GetChildren()) do
	
	local positions = {}
	
	for i, part in ipairs(folder:GetChildren()) do
		positions[tonumber(part.Name)] = part.Position
		part:Destroy()
	end
	
	local totalDistance = 0
	
	local cFrames = {}
	for i = 1, #positions do
		local previousI = i - 1
		if previousI == 0 then previousI = #positions end
		local offset = positions[i] - positions[previousI]
		cFrames[i] = CFrame.lookAt(positions[i], positions[i] + offset)
		
		totalDistance += offset.Magnitude
	end
	
	local startCFrame = CFrame.lookAt(positions[1], positions[2])
	local amount = math.round(10)
	local waitTime = totalDistance / amount / speed
	local targets = {}
	
	for i = 1, amount do
		local target = Instance.new("Part")
		target.Anchored = true
		target.CanCollide = false
		target.CanTouch = false
		target.CFrame = startCFrame
		target.Size = Vector3.new(0, 0, 0)
		target.Transparency = 1
		target.Parent = folder
		
		local attachment1 = Instance.new("Attachment", target)

		local model = game.ServerStorage.Models[folder.Name]:Clone()
		model:SetPrimaryPartCFrame(startCFrame)
		model.Parent = folder

		local attachment0 = Instance.new("Attachment", model.PrimaryPart)

		local alignPosition = Instance.new("AlignPosition")
		alignPosition.Attachment0 = attachment0
		alignPosition.Attachment1 = attachment1
		alignPosition.MaxForce = math.huge
		alignPosition.MaxVelocity = speed
		alignPosition.Responsiveness = 200
		alignPosition.Parent = folder

		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.Attachment0 = attachment0
		alignOrientation.Attachment1 = attachment1
		alignOrientation.MaxTorque = math.huge
		alignOrientation.MaxAngularVelocity = 5
		alignOrientation.Responsiveness = 10
		alignOrientation.Parent = folder

		table.insert(targets, target)
	end
	
	spawn(function()
		wait(5)
		local i = 1
		while true do
			local nextI = i + 1
			if nextI > #positions then nextI = 1 end
			local magnitude = (positions[nextI] - positions[i]).Magnitude
			i = nextI
			
			spawn(function()
				for i, target in ipairs(targets) do
					target.CFrame = cFrames[nextI]
					wait(waitTime)
				end
			end)
			
			wait(magnitude / speed)
		end
	end)	
	
end
1 Like

You can use CollisionGroups to solve this issue.
You can set the collision groups of parts individually, or use a script to automate the process.
More of it can be found here: Collisions | Documentation - Roblox Creator Hub