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: Random Generator still picks the same thing every round,

Previous Thread :: Next Thread 
DrRbx is not online. DrRbx
Joined: 02 Feb 2012
Total Posts: 12
19 Feb 2016 07:46 AM
I have my maps in a model in ServerStorage, and I want my game to pick a different random map every time. This is the code that is inside the main game loop:
local allmaps = maps:GetChildren()
math.randomseed(tick())
local newmap = allmaps[math.random(#allmaps)]:clone()
newmap.Parent = mapholder

Every round it picks the same map and I cant seem to figure out why. Help?


Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
19 Feb 2016 07:52 AM
I'm pretty sure this is the solution:

You have to have a range of numbers for math.random to work.
So in this case, you want it to pick map 1, map 2 or map 3, etc.
This means you have to specify what number you want to start counting from, which is 1 in this case.

To do this, we do as follows:

local newmap = allmaps[math.random(1, #allmaps)]:clone()

Hope this helps.
Let us know if it didn't work for you.
Report Abuse
DrRbx is not online. DrRbx
Joined: 02 Feb 2012
Total Posts: 12
19 Feb 2016 07:56 AM
No that didn't work, it seems to pick something different every time the script runs, so when I test it, but from then it carries on picking the same.


Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
19 Feb 2016 10:29 AM
Add this to the top

math.randomseed(tick())
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
19 Feb 2016 10:29 AM
Ow you did :-)
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
19 Feb 2016 10:34 AM
Unfortunately ROBLOX is not as random as people would like it to be.

You could try something like this after randomseed

for i = 1, math.random(1, 10)
wait(math.random(1, 10) * 0.01)
end

Just to help it get started off. Not sure if that would fix your issue but you can try.
Report Abuse
CaptainGector is not online. CaptainGector
Joined: 02 May 2014
Total Posts: 487
19 Feb 2016 10:39 AM
... Is there only one map in the folder?
Report Abuse
DrRbx is not online. DrRbx
Joined: 02 Feb 2012
Total Posts: 12
19 Feb 2016 11:51 AM
4


Report Abuse
Warlyx is not online. Warlyx
Joined: 08 Feb 2016
Total Posts: 120
19 Feb 2016 12:01 PM
This may be your problem

local random = randoms[math.random(1,#randoms)]


while wait() do
random:clone().Parent = workspace
end

See it will always be the random it chooses, unless you put it inside of the while wait() do, which is an ongoing loop starting over selecting it at random. What I'm saying is, if you want it to select at random, you will need to put it inside of a function as the variable is just stating it needs to have a spot so it can select randomly more than once.



________________________________________________________________________
Report Abuse
Warlyx is not online. Warlyx
Joined: 08 Feb 2016
Total Posts: 120
19 Feb 2016 12:02 PM
therefore it should be;

local randoms = {workspace.Part1,workspace.Part2}

while wait() do
local random = randoms[math.random(1,#randoms)]


random:clone().Parent = workspace
end


________________________________________________________________________
Report Abuse
VertexArray is not online. VertexArray
Joined: 05 Jul 2014
Total Posts: 1804
19 Feb 2016 12:09 PM
Everything OP wrote is fine. I'm not sure what is wrong with randomseed(). I was getting different results in initial start before, but recently it's been outputting the same value.

I think the only workaround for now is to separate your newmap variable (default to nil) and assign it after running your map selection through 2 iterations.



Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
19 Feb 2016 12:22 PM
math.randomseed(tick()%1*1e6)
local allmaps = maps:GetChildren()
local newmap = allmaps[math.random(#allmaps)]:clone()
newmap.Parent = mapholder

Issues boil down to MSBs biasing the LCG, tick() is a terrible source for a seed, setting the seed over and over doesn't make things more random, yada yada yada
Report Abuse
VertexArray is not online. VertexArray
Joined: 05 Jul 2014
Total Posts: 1804
19 Feb 2016 12:27 PM
Works perfectly. Thanks for sharing, Casualist.



Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
19 Feb 2016 12:36 PM
Anytime, sorry if I came off a little blunt. Kinda tired and I usually answer this question every other day. If anyone would like an in depth explanation I'll be happy to write one up proper later in the day
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