Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

too many elseifs for math.random?

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?

2 comments

0

idk

1

if you didnt know why did you comment

2 answers


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()

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]()

This discussion is preserved as it was. New answers, comments, and votes are closed.