How to get a random value from a module script?

local Names = {
	"Test1",
	"Test2",
	"Test3",
	"Test4",
	
	
}


local Name = Names[math.Random(1,#Names)]
print(Name)

return Names

Is my current script but I dont know how to pick a random one out of those

1 Like

You could just make that a function in the modulescript

function Module.GetName()
   return Names[math.random(1, #Names)]
end
1 Like

If you set up another table inside the module, you will be able to get the table size.

Modules are meant to be structured like dictionaries or metatables, so you won’t be able to get the size just by doing “#Names”.

local Names = {
	Names = {
		"Test1",
		"Test2",
		"Test3",
		"Test4",
	}
}

return Names.Names[math.random(1,#Names.Names)]

Also just a quick note, when I ran math.Random() with a capital R, it didn’t work so that could also be why your module wasn’t working. Use math.random() instead.

I think this similar post could be useful to you.