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

How can I use for loops to place parts on a part?

Asked by
Mystdar 352 Moderation Voter
8 years ago

I have a 5x5 part and I want to put a part (called "plate") on each stud of the part, so 25 "plates". I will start in the top left of the part, and move across the z axis and then down the x axis, and across the z axis, etc.

base = game.Workspace.Part
basex = base.Size.X
basez = base.Size.Z

Firstly I want to find the top left stud's position on the part. This doesn't work, I get the error:

upperleft = base.Position - Vector3((basex/2), 0, -(basez/2))

It should go back half of the x axis and then go up (hence the minus minus) half the y axis. 12:24:15.624 - Workspace.Script:4: attempt to call global 'Vector3' (a table value)

Next I want to place the parts:

for x = 1, basex do -- Each x axis the part has
    for z = 1, basez do -- Place a part for each z axis on the x axis
        plate = game.Lighting.Plate:Clone()
        plate.Parent = game.Workspace
        plate.Position =  upperleft + Vector3(x, 0, z)      

I can't test this, because I can't get past the error on line 4.

And finally naming the parts, I want to name the parts depending on their position, like on a grid:

        plate.Name = x..","..z
    end
end

I want my script to work on parts of all sizes. Thanks.

Answer this question