Conveyor script problem

I’m making a game similar to ToH, and I have a conveyor script that looks through the workspace and finds the conveyors and makes it move the player. It all works fine, except sometimes, when a new round starts, the output gets flooded (an error every millisecond).

The error says it’s on line 6, and I forgot what the error said (it’s hard to catch as it happens rarely, and I did an idiot move and decided to not get help, so I lost the error message :pensive: . I’m pretty sure it said something about a parent though. ) This is the script:

local addConveyor = function(c)
	if c.Name == "CONVEYOR" then
		if c.Parent then
			local conveyorPart = c.Parent
			local conveyorSpeed = conveyorPart.CONVEYOR.Value
			conveyorPart:GetPropertyChangedSignal("CFrame"):Connect(function()
				conveyorPart.Velocity = conveyorPart.CFrame.LookVector * conveyorSpeed
			end)
		end
	end
end

workspace.DescendantAdded:Connect(addConveyor)
for i,v in pairs(workspace:GetDescendants()) do
	addConveyor(v)
end

I attempted to fix it by adding if c.Parent but it didn’t work.

1 Like