I've heard of a solution that uses math.randomseed and the tick function, however I don't fully understand it and I don't know how to implement it into this code. The problem is that it chooses the same result everytime.
local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren() function chooseMap() local randomMap = Maps[math.random(1, #Maps)]:Clone() randomMap.Parent = workspace.MapHolder print(randomMap.Name) end chooseMap()
If anyone has any better advice on how to code this more properly and more advanced please let me know in your answer or comment.
So, the way math.randomseed works, you need to kinda know how math.random works. You might think "Oh yeah, it generates a random number from the parameters." This is incorrect. It gets based off what the seed is, but I have not been studying how math.random works so I cannot tell you how it gets a number of the seed. math.randomseed changes the seed.
Here is a good example of math.randomseed
math.randomseed(os.time()) --it just needs a random number, should not be generated with math.random or seed will be same in every server local Print() print(math.random(1, 10) end Print() Print() Print() Print() Print() Print() Print()
However, here is a bad example.
local Print() math.randomseed(os.time()) print(math.random(1, 10) end Print() Print() Print() Print() Print() Print() Print()
Why is this bad? Well, if we fire this function a lot within a second, we will get the same number printed.
Hope this helps!
With math.randomseed, all you need to do is add math.randomseed(tick()) to your code, litterally just in the line above randomMap. By doing this, you change the current "seed" of random possibilites.
Take for example a minecraft world, its all randomly generated around a "seed". While it does something very different with that seed, the principles remain v similair.