New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always. Still have questions? Join our Discord server and get real time help.
0  # Random brick spawning script broken? nonstoppoop639 22
3 years ago
 Part = 1
Wedge = 2
Cylinder = 3

while true do
Instance.new(math.random(1,2,3))
wait(.5)
end


It's supposed to create a random brick that is either Part, Wedge or cylinder.

Part of an exercise I am doing. Thank you! :D

1   jordan0810 55
3 years ago

Good attempt but you have used math.random incorrectly and your variables are useless.

In your code you have told math.random to start at 1, end at 2 and increment by 3 each time. (Which is impossible!) Math.random should be used like this: math.random(starting number, end number, [increment])

Your variables are not getting used in your code so i have replaced them with an array (table)

Below i have changed and fixed your code.

--NilLogic

Objects = { --Define the different objects
"Part",    --Index of 1
"Wedge",  --Index of 2
"Cylinder"   --Index of 3
}

--[[
objects  would return "Part"
objects  would return "Wedge"
objects  would return "Cylinder"

Instance.new(objects)  would create a new part.
Instance.new(objects)  would create a new wedge.
Instance.new(objects)  would create a new cylinder.

Using math.random we can select one of the above commands to be run
math.random(1,3)  will return either 1, 2 or 3

Which allows us to select an object at random.
objects[math.random(1,3)]  would return either "Part", "Wedge" or "Cylinder"

So finally we can create an object at random by combining all the code together.
Instance.new(objects[math.random(1,3)])
--]]

while true do
Instance.new(objects[math.random(1,3)])
wait(.5)
end 0
To add onto this I suggest doing while wait(0.5) do then have an end it just cleans up nicer Prioxis 682 — 3y 0
^ jordan0810 55 — 3y 0
^ Vezious 290 — 3y 