Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I randomly generate parts?

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()

1 comment

0

How exactly do you want the parts spawn? Randomly or a random part when someone touches or clicks something?

2 answers

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)
)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.