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

how to make math.random with strings not just numbers?

this code: local RandomMap = math.random("GreenForest", "some map", "green desert") it doesnt really work but it only works with numbers any help on how to get it working

1 answer

You can do that using arrays, you need to generate number from 1 to size of the array and then pick the generated index from the array, the array will contain strings you need:

local maps = {"GreenForst", "some map", "green desert"}

local random_index = math.random(1, #maps)
local random_map = maps[random_index]

This takes too much lines to write so after bit of shortening you get the following result:

local maps = {"GreenForst", "some map", "green desert"}

local function get_random_map()
	return maps[math.random(1, #maps)]
end

1 comment

0

^^ kudos

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