Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 10 years ago

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

Log in to vote
1
Answered by
RM0d 305 Moderation Voter
10 years ago
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...

Ad
Log in to vote
0
Answered by 10 years ago

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.

0
Use GetChildren... RM0d 305 — 10y
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. BlueTaslem 18071 — 10y
0
Thats what i done... Well called RM0d 305 — 10y

Answer this question