HeatJtwmt
|
  |
| Joined: 07 Nov 2011 |
| Total Posts: 219 |
|
|
| 17 Apr 2017 09:37 AM |
So I'm making a script that randomly selects a Sound inside of a Folder. This just experimental, I'm not actually using it for a game or anything, so things might not be in the most suitable place.
Here's the script:
sounds = game.Workspace.Sounds:GetChildren() while true do ranSound = math.random(1, #sounds) soundChosen = sounds[ranSound] soundChosen:Play() wait(soundChosen.TimeLength) end
I wrote the above script to randomly select a sound, play it, and wait the length of the sound before restarting the loop again.
But instead it selects the first sound I see in the explorer and it goes down the list.
If I'm incorrectly using math.random(), please impart your knowledge so I know how to use it properly in the future.
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 09:41 AM |
sounds[math.random(1,#sounds)]
R$0 |
|
|
| Report Abuse |
|
|
HeatJtwmt
|
  |
| Joined: 07 Nov 2011 |
| Total Posts: 219 |
|
|
| 17 Apr 2017 09:43 AM |
Wouldn't that do the same thing?
I'm making a variable that has a function, and then I'm applying that variable to a table.
You're applying a function to the table, but I'm applying a variable that has a function to a table. Where's the different result?
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 09:44 AM |
GetChildren creates a table.
R$1,097 |
|
|
| Report Abuse |
|
|
HeatJtwmt
|
  |
| Joined: 07 Nov 2011 |
| Total Posts: 219 |
|
|
| 17 Apr 2017 09:45 AM |
I know, which is why I'm applying the table sounds to a function that chooses an object randomly out of said table.
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 11:45 AM |
| I have seen in several threads that math.random() was broken in studio |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2017 11:47 AM |
math.randomseed( tick() ) math.random() --generates same number but gets it out of the way --use ur random after this |
|
|
| Report Abuse |
|
|
Ysko
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 7837 |
|
|
| 17 Apr 2017 12:04 PM |
| If you want it to be *truly* random, then take a look at this wiki page: http://wiki.roblox.com/index.php?title=Random_numbers |
|
|
| Report Abuse |
|
|