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

Help me with sound, working on Studio but not Ingame?

I want to make a playist that plays music on my game. I want to load the next song before it plays so there is no delay (I use music that are more than 2 min long)

The first song plays, but it just does not trigger the ending event...

The thingis that this works in studio, but not ingame, It does not even do the "End" print ingame from the last lines of the script.

I want to know what's breaking my thing and how could I fix it.

This is the script:

local List = {
	[1] = "218607791";
	[2] = "218608165";
	[3] = "218609229";
}

local Music1 = Instance.new("Sound",game.Workspace)
Music1.Name = "Music1"
Music1.Volume = 0.1
local Music2 = Instance.new("Sound",game.Workspace)
Music2.Name = "Music2"
Music2.Volume = 0.1

local Current = Music2		-- I put this there so it changes to the Music1

local num = 1

function change()
	print("Changing")
	if Current == Music1 then
		Current = Music2
		Music2:Play()
		Music1.SoundId = "rbxassetid://"..List[num]
	elseif Current == Music2 then
		Current = Music1
		Music1:Play()
		Music2.SoundId = "rbxassetid://"..List[num]
	end
	
	if num == (#List) then num = 1 else num = num + 1 end
end

Music1.SoundId = "rbxassetid://"..List[1]
change()

Music1.Ended:connect(function()
	print("Ended")
	Music1:Stop()
	change()
end)

Music2.Ended:connect(function()
	print("Ended")
	Music2:Stop()
	change()
end)

1 answer

I'd say this is ROBLOX's fault. They're amateurs when it comes to messing with sounds. Try to make a loop and have it wait Music1's TimeLength and then play Music2, and wait Music2's TimeLength.

while wait() do
	Music1:Play()
	wait(Music1.TimeLength+1) --Give it a small delay
	print("Stopping Music1")
	Music1:Stop()
	change()
	wait(Music2.TimeLength+1)
	print("Stopping Music2")
	Music2:Stop()
	change()
end

You may need to add a few delays so the game has some time to register the TimeLength for Music1 and Music2 for each time you change the SoundID

5 comments

0

But I do not want to add delay, I want to have a smooth music change since I use music with 2-3 files.

0

If you don't want a delay, then simply remove the +1 at the end of each wait

0

Still works only in studio, but not ingame... (it just spams the prints, I tried adding a delay but still does the thing)

0

That means it isn't loading fast enough... Add maybe a wait(5) or wait(10) before the loop

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