Music System with .Ended Sound Event won't emit

I’m currently working on a music system with a preset playlist, However, Whenever I use the .Ended event for the Sound event (in SoundService if that helps) it will not emit nor will changing any of the TimePosition. Anytime I skip a song it will successfully skip it however, it does not replicate to all clients with the TimePosition 0 when the Server says it is at TimePosition 0. After the current song is over the entire system will just stop functioning. I’ve rewrote this system about three times and have no idea what else to do.

--// Music Service \\--
local ReplicatedStorage 	= game:GetService("ReplicatedStorage");
local SoundService 			= game:GetService("SoundService");

--// Music List \\--
local musicList = {2097185619,3548828431,3294968898,4456886461,4602745148,3266991752,2908721473,985278603,3369265206,2911133909,1367367158,4693249464,4277136473}

--// Instances \\--
local areaMusic 			= SoundService:WaitForChild("areaMusic");

--// Remotes \\--
local skipSong 				= ReplicatedStorage:WaitForChild("skipSong");
local playSongEvent 		= ReplicatedStorage:WaitForChild("playSong");
local setVolume 			= ReplicatedStorage:WaitForChild("setVolume");

--// Main Functions \\--
function playSong(soundid)
	print("Got SoundID: ".. soundid)
	local newSoundId = "rbxassetid://" .. soundid;

	--// Sound Instance Handling
	areaMusic:Pause(); -- Stops music for everything below
	areaMusic.TimePosition = 0 -- Just to make sure.
	print("Set TimePosition: ".. areaMusic.TimePosition)
	wait(0.1); -- Allows for a little debounce before setting everything.
	areaMusic.SoundId = newSoundId; -- Sets the SoundId to the one set above.
	areaMusic:Play(); -- Start's song from begining

--// Event Handler \\--
	print("Got Ended Event")
	areaMusic.TimePosition = 0
	playSong(musicList[math.random(1, #musicList)]); -- Just plays a song, randomly will select because no parameter is provides

	playSong(musicList[math.random(1, #musicList)]); -- Same as the ended event above

	playSong(soundid); -- Same as the ended event above

	areaMusic.Volume = volume

--// Initiate \\--
playSong(musicList[math.random(1, #musicList)]) -- Starts the system up.```
1 Like

Just a theory, but can you try parenting the sound to workspace (or if it’s local startergui)?

I think your problem is the skip command is stopping the music, which is an entirely different function. Try adding that to your code.

Ended only fires when the entire sound finishes playing. It won’t fire if it is stopped by the functions Pause() or Stop(). It also won’t fire if the Looped property is true.

I would love to but I need the sound to replicate to the clients correctly in order to correctly use .PlaybackLoudneess for Audio Visualizers

I’m pretty sure that PlaybackLoudness works always, as long as the Client is able to play the Sound. In my test game it’s also parented to Workspace and I have dozens of audio visualizers that run over that property.

I’ll attempt that when I get home and see if anything changes.

Thanks, I fixed it at school but that seemed to do the job.

1 Like