|
| 21 Feb 2017 07:40 AM |
local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren() local randommap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
randommap:Clone().Parent = game.Workspace
It only clones the same thing over and over again
I tried
randommap:Clone().Parent = game.Workspace randommap:Clone().Parent = game.Workspace randommap:Clone().Parent = game.Workspace randommap:Clone().Parent = game.Workspace
And it's literally the same map everytime (unless somehow i got really unlucky like 30 times lol)
|
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 07:45 AM |
you only called math.random() once. try: for i = 1,4 do local randommap = mapsinserverstorage[math.random(1, #mapsinserverstorage)] randommap:Clone().Parent = game.Workspace end |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 07:47 AM |
Oh
Do I change 4 to the amount of maps? |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 07:49 AM |
| ### "for i = 1,4 do" just means ### code inside will repeat 4 times. In other words you need to do a new math.random() call every time you spawn a new map. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 21 Feb 2017 08:10 AM |
put this above your code
math.randomseed(tick())
-- randomseed determines that seed the random generator will use to generate random numbers. Usually in studio it's always the same, but tick() is current seconds since the EPOCH so it's always different
and make more maps so it has more to choose from.
-- Former AKA : luis15232 |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 08:20 AM |
| I tried this but it's still ### same map x = 0 function randommap() math.randomseed(tick()) local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren() local maps = mapsinserverstorage[math.random(1, #mapsinserverstorage)] return maps end if x ## 0 then ########################## = game.Workspace wait(15) ########################## = game.Workspace wait(10) ########################## = game.Workspace end |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 08:20 AM |
| x = 0 function randommap() math.randomseed(tick()) local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren() local maps = mapsinserverstorage[math.random(1, #mapsinserverstorage)] return maps end if x ## 0 then ########################## = game.Workspace wait(15) ########################## = game.Workspace wait(10) ########################## = game.Workspace end |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 08:21 AM |
The tag is
randommap():Clone().Parent = game.Workspace |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 08:35 AM |
| try calling math.randomseed(os.time()); everytime u need a new map. math.random is not 100% random, it is only pseudo random meaning that it uses complex math calculations based off of a seed and then two parameters you give the random function. In this case we are giving a dynamic seed (os.time()) which is always prograssing with the time. |
|
|
| Report Abuse |
|
|
devHoodie
|
  |
| Joined: 04 Nov 2008 |
| Total Posts: 30332 |
|
|
| 21 Feb 2017 08:42 AM |
| ### way you're doing it will always clone ### original map stored inside of randommap. Because you never changed randommap to a different map.. -- Former AKA : luis15232 |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2017 09:05 AM |
Still the same problem, it only loads the same map everytime I run it
math.randomseed(os.time()) local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren() local randommap = mapsinserverstorage[math.random(2, #mapsinserverstorage)] wait(1) randommap:Clone().Parent = game.Workspace
|
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 09:25 AM |
| Calling math.random returns it right away, you don't get a new return by calling the variable again. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 09:32 AM |
| I tested it multiple times and everytime I would load up the game, it would always be the same map |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 09:54 AM |
create models of each map, and through the site get their ids, then store the map model ids in a table (i will assume for brevity that there are 3 maps) local maps = {123456, 987654, 876542}; math.randomseed(os.time()); local index = math.random(1, table.getn(maps)); local map = game:GetService("InsertService"):LoadAsset(maps[index]); map.Parent = game.Workspace; --move the map to your desired position: map:MoveTo(Vector3.new(0, 500, 0)); --also make sure you destroy the old map if there is one when you are getting ready to insert a new map: map:Destroy(); --or you could use DebrisService to destroy it: game:GetService("Debris"):AddItem(map, 3 * 60);
hopefully this helps you |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 09:57 AM |
oops i forgot one thing, because insertservice inserts the map inside of a model, instead of simply declaring a map var do the following: local map_model = game:GetService("InsertService"):LoadAsset(maps[index]); local map = map_model:FindFirstChild("Your maps name here"); map.Parent = game.Workspace; map_model:Destroy(); --this only destroys the empty model that the map was packaged in upon insert, NOT the actual map. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2017 11:36 AM |
Error popped up
12:34:56.345 - Workspace.Script:10: attempt to index local 'map' (a nil value)
My code:
local maps = {387796137, 377204154}; print("h") math.randomseed(os.time()); local index = math.random(1, table.getn(maps)); print("b") local map_model = game:GetService("InsertService"):LoadAsset(maps[index]); print("e") local map = map_model:FindFirstChild("Your maps name here"); map.Parent = game.Workspace; print("yo") |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2017 12:26 PM |
| make sure the statement with FindFirstChild actually returns something. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2017 05:10 PM |
| When it says "Your Name Here" put the name of your map model instead. |
|
|
| Report Abuse |
|
|