|
| 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 |
|
|
|
| 21 Jun 2014 01:34 PM |
bump34Pap
*Get jazzy on me.* |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 14 Mar 2013 |
| Total Posts: 1115 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 12 Jun 2014 |
| Total Posts: 148 |
|
|
| 22 Jun 2014 07:51 AM |
| EVERYTHING IS AWESOME!!! i love watch The Lego Movie |
|
|
| Report Abuse |
|
|