generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Why is this not random?

Previous Thread :: Next Thread 
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
Mister_Manakin is not online. Mister_Manakin
Joined: 16 Sep 2009
Total Posts: 1935
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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
21 Feb 2017 07:47 AM
Oh

Do I change 4 to the amount of maps?
Report Abuse
Mister_Manakin is not online. Mister_Manakin
Joined: 16 Sep 2009
Total Posts: 1935
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 is online. 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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
21 Feb 2017 08:21 AM
The tag is

randommap():Clone().Parent = game.Workspace
Report Abuse
MICHEAL1988351 is online. MICHEAL1988351
Joined: 26 Jan 2015
Total Posts: 582
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 is online. 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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
21 Feb 2017 08:58 AM
oh I see
Report Abuse
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
Exeriousless is not online. Exeriousless
Joined: 13 Nov 2012
Total Posts: 160
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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
MICHEAL1988351 is online. MICHEAL1988351
Joined: 26 Jan 2015
Total Posts: 582
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
MICHEAL1988351 is online. MICHEAL1988351
Joined: 26 Jan 2015
Total Posts: 582
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
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
21 Feb 2017 11:28 AM
Alright thanks
Report Abuse
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
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
Mister_Manakin is not online. Mister_Manakin
Joined: 16 Sep 2009
Total Posts: 1935
21 Feb 2017 12:26 PM
make sure the statement with FindFirstChild actually returns something.
Report Abuse
Externalization is online. Externalization
Joined: 21 Aug 2013
Total Posts: 13230
21 Feb 2017 02:21 PM
helpppppppppp
Report Abuse
MICHEAL1988351 is online. MICHEAL1988351
Joined: 26 Jan 2015
Total Posts: 582
21 Feb 2017 05:10 PM
When it says "Your Name Here" put the name of your map model instead.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image