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

Is it possible to take math.random on a module script?

So i have an module script i want to take math.random() information from but it wont work i want it to print "Hole1" or "Hole2" cause thats the only two i have left but i don't want to write print(math.random(Module.Hole1)) every time i want that map i want to to be random and if i add another map name to the module script then it would print the choosen map

Heres the module script:

local Holes = {
	Strokes = 0,
	["Hole1"] = {
		["ss"] = 1,
		["gg"] = 2,
		["hh"] = 3,
		["sss"] = 4,
		["assaggasg"] = 5,
		["hdhjhdjdj"] = 6
	}	,
	["Hole2"] = {
		["fhjdfudfui"] = 1,
		["random"] = 2,
		["random one more"] = 3,
		["idk whu"] = 4,
		["i sjould now"] = 5,
		["hello"] = 6
	}		
}

return Holes

That is just random map names for now

Here's the server script:

print(math.random(Module))

1 comment

0

You could just make the module script do math.random by itself, so you just have to do print(Module)

1 answer

✓ Accepted answer

math.random doesn't work like you think it does: it won't select a random member of the Table, you have to use the number it gives to select the corresponding member:

randomHole = Module["Hole" .. math.random(#Module - 1)]

You need to structure the Table better to make this line less complex.

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