Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

too many elseifs for math.random?

Asked by 2 months ago
while wait(5) do
    local r = math.random(1,10)
    if r == 1 then
        randomstuff()
    elseif r == 2 then
        otherrandomstuff()
    end
end

doing this much elseifs makes the code look bigger than it needs to be

how would i make this smaller?

0
idk Coperncius 0 — 2mo
0
if you didnt know why did you comment Bloxulen 87 — 2mo

2 answers

Log in to vote
2
Answered by 2 months ago

while wait(5) do local numberTable = 1, 2 local r = math.random(1,10) for i,v in pairs[numberTable] if v = 1 then randomstuff() if v = 2 then otherrandomstuff()
Ad
Log in to vote
0
Answered by
enes223 39
20 days ago
Edited 20 days ago
local functions = setmetatable({},{__index = functions})

functions.first = function()
print(1)
end

functions.second = function()
print(2)
end

local random = Math.random(0,2)
random = math.floor(random)

functions[random]()

Answer this question