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

When is the best time to put a math.random, when you're picking a map?

I'm still learning how to use math.random, so could someone teach me how to use it, and when would be a good time to put the piece of code in a script?

2 answers

maps =  game.ServerStorage.Maps:GetChildren() -- put the maps in ServerStorage under a model named "Maps"
mapselected = maps [math.random(1, #maps )] -- Chooses a random map
map = mapselected:Clone() -- clones the map
map.Parent = workspace -- sets the parent to workspace

Any Problems comment below. If I helped upvote me please...

I think you would first have an array of the maps you have. Then to get a random map, you would do math.random(1, #array), and then put the selected map into Workspace. So for instance:

myTable = {game.ServerStorage.Map1, game.ServerStorage.Map2, game.ServerStorage.Map3} -- [[I put the maps in ServerStorage]]
mapselected = math.random(1, #myTable) --random map
myTable[mapselected].Parent = Workspace -- put the selected map in Workspace

Something like that.

3 comments

0

Use GetChildren...

0

Things other than maps could be in ServerStorage. The smart thing would be to put all maps in a sub folder of ServerStorage (ServerStorage.Maps) and use GetChildren there.

0

Thats what i done... Well called

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