#my code isn't working

1 messages · Page 1 of 1 (latest)

glacial anvil
#

it is only printing "b" instead of printing "a" sometimes to. what should i do?

button.Touched:Connect(function()
    local numbers = {
        ["a1"] = 1,
        ["a2"] = 2,
        ["a3"] = 3,
    }
    
    local i = math.random(1, 3)
    local randomNumber = numbers[i]
    
    if randomNumber == 1 then
        print("a")
    else
        print("b")
    end
end)
eager osprey
#

the randomNumber variable is a nil

glacial anvil
#

thank you a lot

#

i also wanted to change the "3" inside math.random to some variable so i could change the max of random nunbers with a certain condition

#

but i think math.random doesnt accept variables inside

eager osprey
#

it doesnt matter if its variable or not, it just has to be a number

glacial anvil
#

before i have used a variable that was equal the number of items inside numbers (like #numbers) and it was not working