Randomize Tables

local Maps = {"Camp", "Theater", "Factory"} -- Example Maps

function PickMap()
	--
	local RandomMap = math.random(Maps)
	print(RandomMap)
	--
end

PickMap()

I’m trying to randomize the table: Maps but when I call math.random it expects a number, when Maps is a table/string.

Any help is appreciated!

math.random only accepts & returns integers. Try passing in the amount of strings in the table.

local Maps = {"Camp", "Theater", "Factory"} -- Example Maps

function PickMap()
	--
	local RandomMap = Maps[math.random(#Maps)]
	print(RandomMap)
	--
end

PickMap()

Thank you so much, that works perfectly!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.