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: How would you get a music script to be.. random?

Previous Thread :: Next Thread 
ArbitraryNewt is not online. ArbitraryNewt
Joined: 13 Jan 2009
Total Posts: 3185
21 Jun 2014 01:28 PM
I've been making scripts that have order, as in the songs go the same way every time on a loop.
But how would I get the script to play a randomly selected song of the few I put in?

(What I've been doing so far.)

while true do

sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=157171368"
sound.Parent = game.Workspace
sound:Play()
wait(200)
sound:Remove()
.. and so on

*Get jazzy on me.*
Report Abuse
ArbitraryNewt is not online. ArbitraryNewt
Joined: 13 Jan 2009
Total Posts: 3185
21 Jun 2014 01:34 PM
bump34Pap

*Get jazzy on me.*
Report Abuse
Xeptix is online. Xeptix
Joined: 14 Mar 2013
Total Posts: 1115
21 Jun 2014 02:53 PM
1) :Remove() = bad idea, pls no

2) This is not Scripting _HELPERS_, this is _SCRIPTERS_

2) What you're looking for is tables, and math.random. Here are some references that will assist you, I can, though I refuse to code this for you.

http://wiki.roblox.com/index.php/Table
http://wiki.roblox.com/index.php/math.random
Report Abuse
Xeptix is online. Xeptix
Joined: 14 Mar 2013
Total Posts: 1115
21 Jun 2014 02:55 PM
said 2) twice, darn.
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
21 Jun 2014 05:22 PM
sounds = {157171368,157171368,157171368,157171368,157171368}


while true do
local id = sounds[math.random(1,#sounds)]
sound.SoundId = "http://www.roblox.com/asset/?id="..id
sound:Play()
sound:Play()
wait(200)
sound:Stop()
end
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
21 Jun 2014 06:14 PM
+ might want to add some extra code to make it not play the same song twice in a row
Report Abuse
CoolioTree is not online. CoolioTree
Joined: 26 Dec 2012
Total Posts: 2509
21 Jun 2014 06:15 PM
I'M SO HYPER





DUN DUN DUN





I'M AWN W33D





DUN DUN DUN



I'M SO HYPER
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
21 Jun 2014 06:18 PM
sounds = {157171368,157171368,157171368,157171368,157171368}

sound = Instance.new("Sound")

heres one way to do it

function shuffle(lastId)
local newId = sounds[math.random(1,#sounds)]
if newId == lastId then
repeat
newId = sounds[math.random(1,#sounds)]
wait()
until newId ~= lastId
end
return newId
end


while true do
local last = sound.SoundId
local id = shuffle(lastId)
sound.SoundId = "http://www.roblox.com/asset/?id="..id
sound:Play()
wait(200)
sound:Stop()
end
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
21 Jun 2014 06:25 PM
U do it rong.

You need two tables
local available={1,2,3,4,5,6}
local recent={7,8,9}

When you use a sound you move it from available to end of recent (recent is a queue) and move the first item of recent back to available.

You adjust how many there are in recent at a time to balance between randomness and hearing a recent song instead of a not so recent one.
Report Abuse
DarkKairo is not online. DarkKairo
Joined: 12 Jun 2014
Total Posts: 148
22 Jun 2014 07:51 AM
EVERYTHING IS AWESOME!!! i love watch The Lego Movie
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