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 » Scripting Helpers
Home Search
 

Re: math.random()

Previous Thread :: Next Thread 
devRaver is not online. devRaver
Joined: 08 Apr 2013
Total Posts: 531
10 Apr 2014 07:38 PM
I have an error, to my comprehension math.random(1,#tablename) should take only value away from a table, right?

If that so happens to be the case, why does it take a lot more than 1 value away from where it's linked. Here's my script:

function Check()
Limiteds = game.Workspace.MainValues:GetChildren()
for i,v in ipairs(Limiteds) do
Limited = Limiteds[math.random(1,#Limiteds)]
CurrentItem.Value = Limited.Value
LimitedName.Text = CurrentItem.Value
LimitedPicture.Image = Limited.Image.Value
LimitedPrice.Text = Limited.Price.Value
Limited.Parent = game.ServerStorage
end
Start()
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 07:41 PM
'why does it take a lot more than 1 value away from where it's linked. Here's my script:'
Could you elaborate.

Do you mean it's sometimes giving you the same value from before or?
Report Abuse
devRaver is not online. devRaver
Joined: 08 Apr 2013
Total Posts: 531
10 Apr 2014 07:45 PM
Ok, so there's a model in Workspace named "MainValues", inside it are 18 values. I upon math.random() it also alters the values parent to ServerStore, so it doesn't show up again.

I was expecting math.random(1,#tablename) to merely take 1 of those 18 values every minute or second in this case to test. However, I noticed in Test Mode, it functioned well, but after the 3rd or so legitimate value, the same vale kept occurring. I went to check the Workspace, and noticed that all the values had moved to ServerStorage. I played again, whilst observing Workspace, and noticed that more than 1 value was being taken away.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 07:49 PM
'Limiteds = game.Workspace.MainValues:GetChildren()'
Is going to create a table that does not update when some reference in the table has changed parent. So you would have to do something like:

Limiteds = game.Workspace.MainValues:GetChildren()
for i,v in ipairs(Limiteds) do
Limited = table.remove(Limiteds, math.random(1,#Limiteds))

Or something of the sort (If I'm understanding your problem correctly)
Report Abuse
devRaver is not online. devRaver
Joined: 08 Apr 2013
Total Posts: 531
10 Apr 2014 07:52 PM
I tried your script; same problem.
It starts with 18 values, then awkwardly drops down to 9 values, then 4, 3, 2, 1.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 07:54 PM
I don't really understand your problem.

So you have 18 values, and every time the loop is run you want a _different_ value to be moved, right? And your problem is that it is sometimes choosing ones that have already been moved?
Report Abuse
devRaver is not online. devRaver
Joined: 08 Apr 2013
Total Posts: 531
10 Apr 2014 07:57 PM
The function gets the children from MainValues. Each time the function is called, a popup GUI with the limited information comes up, as it does this, the limited information from MainValues is removed. But it removes more than 1. However, I've fixed this:

Limited = table.remove(Limiteds, wait(1), math.random(1,#Limiteds))

Thank you for helping anyway! ;D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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