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

How would I randomly generate parts?

Asked by 9 years ago

I know how to sort of do it, but Im not positive. I want it to keep on looping so it keeps on generating Heres what I have so far

Block=Instance.new('Part')
    Part.Size=5,5,5
    Part.Color=Bright red
    Part.Position=math.random
end

while true wait()
0
How exactly do you want the parts spawn? Randomly or a random part when someone touches or clicks something? F_lipe 135 — 9y

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

I would like to add to what theD1R3W0LF said.

First, Color is not a property of Part; the name is BrickColor.

Second, the BrickColor is not a string. It's a BrickColor. It is therefore edited by this;

part.BrickColor = BrickColor.new("Really red")

Third, to make a brick spawn in a random position, we need three random numbers for height, width, and depth. We don't want it to spawn ABSOLUTELY anywhere, though, because most of the time it wouldn't be anywhere you could see.

part.Position = Vector3.new(
--x
math.random(-100,100),
--y
math.random(1,100),--So it doesn't spawn below the baseplate
--z
math.random(-100,100)
)
Ad
Log in to vote
0
Answered by 9 years ago

There are many problems here. 1. Part is not defined, try using you initial variable Block 2. There is a useless end there. 3. Lines 1-4 are only called once. 4. math.random is not the correct way of defining a place. - math.random is also missing parameters (low, high) 5. 5,5,5 is not the correct way of defining a size 6. For the color, use quotation marks to make sure you aren't using a variable.

To fix this use:

x = math.random(1,10)
while true do
    local part = Instance.new('Part')
            part.Size = Vector3.new(5, 5, 5)
        part.BrickColor = "Bright red"
        part.Position =  Vector3.new(x, x, x)
    wait(0.5)
end

With this, it will only spawn bricks in a certain area

Answer this question