Alright so here's what I have so far. I have bricks, called "Rainbow Bricks", located in a PartStorage model in the workspace. I'm trying to build a circular conveyor belt, with everything that lands on it going towards the middle. I think the easiest way to do that is to make the center part of the conveyor, the collector, have some sort of black hole script to pull only those certain bricks in towards it. Now here's what I know

if object is rainbow brick, then add it into a table
if the relative position (collector position - part position) is less than 25 then
insert a BodyPosition into the children with less than 25 relPos
BodyPosition.position = collector.position
BodyPosition.maxForce = x

Seems simple enough, right? Well here's my attempt

local hole = script.Parent
local childList = {}

function checkObject(obj)
	if (obj ~= hole) and (obj.className == "Part") and obj.Name=="Rainbow Brick" then
		if (obj.Anchored == false) then
			table.insert(childList, 1, obj)
		end
end

checkObject(workspace)

	local child = childList[n]
	if (child ~= hole) and (child.className == "Part") and (child.Anchored == false) and (child.Name=="Rainbow Brick") then
		local relPos = hole.Position - child.Position
		local motivator = child:FindFirstChild("BlackHole Influence")
		if relPos.magnitude < 25 then
				if motivator == nil then
					motivator = Instance.new("BodyPosition")
					motivator.Parent = child
					motivator.Name = "BlackHole Influence"
				end
				motivator.position = hole.Position
				motivator.maxForce = 200
			end
		elseif child.motivator ~= nil then
			child.motivator:Remove()
		end
	end
end


-- 

No errors in the output, nothing is happening. I'm sorry if this script is terrible. I'm still a beginner.

2 comments

0

You're not connecting it to a function. Therefore what you're trying to do is never going to happen, unless you make a function and connect it to an event

0

I sort've understand, that was pretty stupid of me. So the first part where the table is created is OK right? I'm new to tables. The second part I have to create a function around it