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: math.random() isn't working?

Previous Thread :: Next Thread 
HeatJtwmt is not online. 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
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
17 Apr 2017 09:41 AM
sounds[math.random(1,#sounds)]



R$0
Report Abuse
HeatJtwmt is not online. 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
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
17 Apr 2017 09:44 AM
GetChildren creates a table.


R$1,097
Report Abuse
HeatJtwmt is not online. 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
Diligent_Coder is not online. Diligent_Coder
Joined: 20 Jul 2011
Total Posts: 1314
17 Apr 2017 11:45 AM
I have seen in several threads that math.random() was broken in studio
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is online. 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
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