Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My audio shuffle script has problems, what's up with it?

I'm making a shuffle script (Play a random audio in the list), which doesn't work. Not only does the audio not play anymore (Does in studio, but the next song starts at halfway for some reason) but when i try and use wait(music.TimeLength) it goes crazy and won't work properly. So i used the ended function which brings me here. It only works in studio as i said, and even there not properly. I need it to work ingame + properly.

wait(0.1)



song1 = "http://www.roblox.com/asset/?id=348452202" -- Diplo & Sleepy Tom - Be Right There
song2 = "http://www.roblox.com/asset/?id=235672613" -- Years & Years - Desire
song3 = "http://www.roblox.com/asset/?id=335856846" -- Craig David - When the Bassline Drops   
song4 = "http://www.roblox.com/asset/?id=258218642" -- Lean on
song5 = "http://www.roblox.com/asset/?id=348130053" -- Sigala - Say You Do
song6 = "http://www.roblox.com/asset/?id=366818956" -- DJ Snake - Middle
song7 = "http://www.roblox.com/asset/?id=341409912" -- 67 (Mental K, Dimzy, Monkey, Smallz)
song8 = "http://www.roblox.com/asset/?id=400165614" -- Mike Posner - I Took A Pill In Ibiza (Seeb Remix)
song9 = "http://www.roblox.com/asset/?id=342921010" -- Roses - The Chainsmokers ft. ROZES
song10 = "http://www.roblox.com/asset/?id=324474850" -- 99 Souls - The Girl is Mine 
song11 = "http://www.roblox.com/asset/?id=397950586" -- Calvin Harris & Disciples - How Deep Is Your Love
song12 = "http://www.roblox.com/asset/?id=225214406" -- Lost Frequencies - Are you with me
song13 = "http://www.roblox.com/asset/?id=345686522" -- Flume (feat. Kai) - Never Be Like You
song14 = "http://www.roblox.com/asset/?id=239028897" -- GTA - Intoxicated
song15 = "http://www.roblox.com/asset/?id=208170888" -- Felix Jaehn - Ain't Nobody (Loves Me Better) 
song16 = "http://www.roblox.com/asset/?id=398856245" -- Skepta - Man
song17 = "http://www.roblox.com/asset/?id=291846600" -- JME - Man Don't Care
song18 = "http://www.roblox.com/asset/?id=401722473" -- Blonde Ft. Craig David - Nothing Like This
song19 = "http://www.roblox.com/asset/?id=362353405" -- Robin Schulz - Sugar
song20 = "http://www.roblox.com/asset/?id=161499083" -- Disclosure - White noise
song21 = "http://www.roblox.com/asset/?id=236597881" -- Natalie La Rose ft. Jeremih (Somebody)
song22 = "http://www.roblox.com/asset/?id=325698676" -- Galantis - Runaway (U & I)
song23 = "http://www.roblox.com/asset/?id=409557291" -- 10/10 swagman woutman awesome wouter song



local music = Instance.new("Sound") 
music.Archivable = true 




music.Parent = script.Parent 

music.Pitch = 1
            
music.Volume = 0.3 
                  

music.Looped = false 


music.Name = "Player"

music.SoundId = "http://www.roblox.com/asset/?id=12222054"
music:play()





music.Ended:connect(function()
	


local songs = {song1,song2,song3,song4,song5,song6,song7,song8,song9,song10,song11,song12,song13,song14,song15,song16,song17,song18,song19,song20,song21,song22,song23}
local song = math.random(1,#songs)
local var = song
print("Playing Sound"..song)
--script.Off.Value = false
--script.Song.Value = "Song"..song
wait(0.01)
music.SoundId = songs[song]
music:play()
end)


1 answer

✓ Accepted answer

Here is a much easier approach to your problem, make a table full of the song IDs, then pick out a random one and play it each time. You were also missing a various number of things, such as a website link in line 67

This script works perfectly when put in workspace:

wait(0.1)
local songIds = {348452202, 235672613, 335856846, 258218642, 348130053, 366818956, 341409912, 400165614,342921010,324474850,397950586,225214406, 345686522, 39028897, 208170888, 398856245, 291846600, 401722473, 362353405, 161499083, 236597881, 325698676, 409557291}


--[[
348452202 -- Diplo & Sleepy Tom - Be Right There
235672613 -- Years & Years - Desire
335856846 -- Craig David - When the Bassline Drops   
258218642 -- Lean on
348130053 -- Sigala - Say You Do
366818956 -- DJ Snake - Middle
341409912 -- 67 (Mental K, Dimzy, Monkey, Smallz)
400165614 -- Mike Posner - I Took A Pill In Ibiza (Seeb Remix)
342921010 -- Roses - The Chainsmokers ft. ROZES
324474850 -- 99 Souls - The Girl is Mine 
397950586 -- Calvin Harris & Disciples - How Deep Is Your Love
225214406 -- Lost Frequencies - Are you with me
345686522 -- Flume (feat. Kai) - Never Be Like You
239028897 -- GTA - Intoxicated
208170888 -- Felix Jaehn - Ain't Nobody (Loves Me Better) 
398856245 -- Skepta - Man
291846600 -- JME - Man Don't Care
401722473 -- Blonde Ft. Craig David - Nothing Like This
362353405 -- Robin Schulz - Sugar
161499083 -- Disclosure - White noise
236597881 -- Natalie La Rose ft. Jeremih (Somebody)
325698676 -- Galantis - Runaway (U & I)
409557291 -- 10/10 swagman woutman awesome wouter song
--]]

local music = Instance.new("Sound") 
music.Archivable = true 
music.Parent = script.Parent 
music.Pitch = 1
music.Volume = 0.3 
music.Looped = false 
music.Name = "Player"
music.SoundId = "http://www.roblox.com/asset/?id=12222054"
music:play()

music.Ended:connect(function()
	local song = math.random(1,#songIds)
	local var = song
	print("Playing Sound"..song)
	--script.Off.Value = false
	--script.Song.Value = "Song"..song
	wait(0.01)
	music.SoundId = "http://www.roblox.com/asset/?id="..songIds[song]
	music:play()
end)

1 comment

0

Thank you! It works :D

This discussion is preserved as it was. New answers, comments, and votes are closed.