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

Generating parts within a set area?

Asked by 8 years ago

I've been working for about an hour now and for the life of me I cant seem to figure out how to randomly generate parts within an area. I've made a part 100x2x100 and I've been trying to fit 10x10 parts inside of it that have random properties. The random properties I can do but I cant wrap my head around the math.

2 answers

Log in to vote
1
Answered by 8 years ago

Looks like you're trying to make a grid. The correct way to do this would be Numerical For Loops.

local int = 5

for x = -int, int - 1 do
    for z = -int, int - 1 do
        local part      = Instance.new("Part", workspace)
        part.Size       = Vector3.new(10, 2, 10)
        part.Position   = Vector3.new(x*10, 1, z*10)
    end
end
Ad
Log in to vote
1
Answered by
LostPast 253 Moderation Voter
8 years ago

You simply take the outside most positions as parameters. So for your 100X2X100 part, if it is at position 0,0,0.

Take half of 100(50) so it it 50 in each direction.

while wait() do
local p = Instance.new("Part",game.Workspace)
p.Anchored = true
p.Size = Vector3.new(10,10,10)
p.CFrame = CFrame.new(math.random(-50,50),7,math.random(-50,50))
end

math.random gives you a random number inbetween your parameters.

Hope This Helps :)

Answer this question