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.
Log in to vote

Random brick spawning script broken?

Asked by 3 years ago
 Part = 1
Wedge = 2
Cylinder = 3    

    while true do,2,3))

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 answer

Log in to vote
Answered by 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.


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

objects[1]  would return "Part"
objects[2]  would return "Wedge"
objects[3]  would return "Cylinder"[1])  would create a new part.[2])  would create a new wedge.[3])  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.[math.random(1,3)]) 

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

Answer this question