Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to correctly use BodyPosition?

Asked by
Scerzy 85
9 years ago

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

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

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

01local hole = script.Parent
02local childList = {}
03 
04function checkObject(obj)
05    if (obj ~= hole) and (obj.className == "Part") and obj.Name=="Rainbow Brick" then
06        if (obj.Anchored == false) then
07            table.insert(childList, 1, obj)
08        end
09end
10 
11checkObject(workspace)
12 
13    local child = childList[n]
14    if (child ~= hole) and (child.className == "Part") and (child.Anchored == false) and (child.Name=="Rainbow Brick") then
15        local relPos = hole.Position - child.Position
View all 33 lines...

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

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 GeezuzFusion 200 — 9y
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 Scerzy 85 — 9y

Answer this question