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

This script works in studio, but not in-game?

SongOneId = 181547615
SongTwoId = 143959455
SongThreeId = 191819419
SongFourId = 131149175
SongFiveId = 151667588
SongSixId = 165719962
SongSevenId = 192805609
SongEightId = 252872782
SongNineId = 196183054
SongTenId = 210232032

Model = script.Parent
Music = Model.Music

while wait() do
	-- Song One (start)--------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongOneId
	Music:Play()
	wait(Music.TimeLength)
	-- Song One (end)
	-- Song Two (start)--------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongTwoId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Two (end)
	-- Song Three (start)------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongThreeId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Three (end)--------------------------------------
	-- Song Four (start)-------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongFourId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Four (end)---------------------------------------
	-- Song Five (start)-------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongFiveId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Five (end)---------------------------------------
	-- Song Six (start)--------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongSixId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Six (end)----------------------------------------
	-- Song Seven (start)------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongSevenId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Seven (end)--------------------------------------
	-- Song Eight (start)------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongEightId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Eight (end)--------------------------------------
	-- Song Nine (start)-------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongNineId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Nine (end)---------------------------------------
	-- Song Ten(start)---------------------------------------
	Music.SoundId = "http://roblox.com/asset/?id="..SongTenId
	Music:Play()
	wait(Music.TimeLength)
	-- Song Ten (end)----------------------------------------
end	

In studio, it cycles through the songs as it's supposed to, but when I go to play the game on the ROBLOX website, all of the songs play at once, and for just about a second.

4 comments

0

Is this a Script or a LocalScript?

0

Regular script

0

I just tried it as a LocalScript and now it doesn't play at all.

0

Do note (Thanks to GoulStem) sometimes the script will run before the player loads, That's when WaitForChild comes in, Do try it.

1 answer

✓ Accepted answer

What is the purpose of this script? Do you want to put this globally, like in a boombox? Or do you want to play this locally?

If you want to play this globally, where everybody can hear it, keep your script, but shorten it with a "for" loop and a table.

SongTable = {181547615, 143959455, 191819419, 131149175, 151667588, 165719962, 192805609, 252872782, 196183054, 210232032}

Model = script.Parent
Music = Model:WaitForChild("Music")
-- Even though it will load before the server script run, this method is there just in case

while wait() do
	for i, SongID in pairs(SongTable) do
		Music.SoundId = "http://www.roblox.com/asset/?id=" .. SongID
		repeat
			wait()
		until Music.TimeLength > 0
		--[[

		I printed out the TimeLength in the server before I implemented the
		"repeat" loop, and it turns out that the TimeLength is 0. Could be
		because the script is running way too fast to let the Sound object
		read the length of the audio file.

		--]]
		Music:Play()
		wait(Music.TimeLength)
		Music:Stop() -- Why not?
	end
end

Else put the Sound in the local script and parent it to StarterGui.

SongTable = {181547615, 143959455, 191819419, 131149175, 151667588, 165719962, 192805609, 252872782, 196183054, 210232032}

Music = script:WaitForChild("Music")

while wait() do
	for i, SongID in pairs(SongTable) do
		Music.SoundId = "http://www.roblox.com/asset/?id=" .. SongID
		repeat
			wait()
		until Music.TimeLength > 0
		Music:Play()
		wait(Music.TimeLength)
		Music:Stop()
	end
end

1 comment

0

not that it matters, but it bugs me. Use tostring(SongID).

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