Your issue is that math.random is picking a random integer between 1 and 3, 6, 9, 10, or whichever one gets picked. This means it can also pick 2, 4, 5, and basically any number between 1 and 10 that you don’t want.
Make the math.random(1,4). and do:
local chosenNum = numbers[num]
if chosenNum == 3 then
-- stuff
end
Also there is no need for multiple if statements, a simple dictionary as I described above would reduce the need for those and improve performance speed, due to fewer criterias while executing. Using multiple if statements for every single criteria is sure to add a couple extra thousand microns to the function.
Yes, but in this case she is using the table to define number values. No need to define a different color for each value when you can simply check if it equals 3 and make it red.
Edit: I should clarify that you’re right, if multiple colors are being used then you should use a dictionary as you described. In this case though where all we are doing is making a part Really Red if it equals 3, a simple if statement should do.
It works fine as @Y35X suggested if you would shorten my dictionary to an array like:
colors = {"green", "red", "orange"}
local number = math.random(1, #colors)
print(colors[number].." was rolled !")
This way you will keep the number as well as the color.
@TheCarbyneUniverse’ solution may just “work” however my notice was that it involves using multiple if statements for every color, because you would check it like
if n = 3 then
else
if n = 4 then
else
etc...
which would work but be less optimized, his solution was probably to let you know how to compare values but note that that doing this for various values as in your case would take up too much unnecessary lines of code.