Sound wont play

I have a system that is supposed to change the SoundID, and then play that new SoundID, and it cycles through a queue. The SoundID of the Sound is changing, but everytime it changes, it doesn’t actually play it. (Playing gets set to false, despite the fact that it should be true.)

local MarketplaceService = game:GetService("MarketplaceService");
local ReplicatedStorage = game:GetService("ReplicatedStorage");

local sound = ReplicatedStorage.Sound; -- who the hell knows where to store sound anymore

local requests = {};
local default = {
	130768805, -- id in the sound basically
	177505826,
	135308045
}

sound.Ended:Connect(function()
	if (requests[1]) then
		sound.SoundId = "rbxassetid://"..requests[1];
		table.remove(requests, 1);
	else
		sound.SoundId = "rbxassetid://"..default[1];
		table.insert(default, table.remove(default, 1));

		sound:Play();
	end
end)

ReplicatedStorage.RemoteEvents.RequestEvent.OnServerEvent:Connect(function(player, id) -- possibly use onserverinvoke or check id on client too :shrug:
	local success, response = pcall(MarketplaceService.GetProductInfo, MarketplaceService, id, Enum.InfoType.Asset); -- some spicy checking

	if (success and response.AssetTypeId == 3) then
		table.insert(requests, id);
	end
end)

Set Looped to false and Playing to true in the sound properties

Looped is already set to false, and playing is already set to true.

Did you set the sound id in the sound properties so it actually plays a song so .Ended can fire?

If you don’t wanna set the sound id manually, you can just do something like this

local MarketplaceService = game:GetService("MarketplaceService");
local ReplicatedStorage = game:GetService("ReplicatedStorage");

local sound = ReplicatedStorage.Sound; -- who the hell knows where to store sound anymore

local requests = {};
local default = {
	130768805, -- id in the sound basically
	177505826,
	135308045
}

local function Play()
	if (requests[1]) then
		sound.SoundId = "rbxassetid://"..requests[1];
		table.remove(requests, 1);
	else
		sound.SoundId = "rbxassetid://"..default[1];
		table.insert(default, table.remove(default, 1));

		sound:Play();
	end
end

Play()

sound.Ended:Connect(function()
	Play()
end)

Try putting the sound in workspace instead of replicated storage

Works fine in replicated storage

I did set the sound id in the sound properties, and it cycles through the queue once, then it just stops playing, but still changes the SoundID. I think it might be an engine bug.

Try raising the volume of the sound maybe it’s too quiet

The sound just doesn’t play. I am 110% certain it has nothing to do with the volume lol

I just noticed that you never actually played the sound if there is a request. Add sound:Play() to the if statement.

Okay, I see what you mean now. It just looks like the sound doesn’t load properly in ReplicatedStorage so try moving it to workspace

1 Like

Yep, that ended up working. Roblox engineers gotta fix up loading sounds in replicatedstorage lol

1 Like

i played around with it a bit more, and it just bugged out again. this time, the first song played completely fine, but the second song started at 150 seconds in, and the third song just didn’t play at all

Try setting the TimePosition of the song to 0 before you play it?

Try putting the sound in SoundService

Still no luck with getting the sound to work

you changed local sound to game.SoundService.Sound right?

Yes, I did. The problem is that the sound will sometimes play and sometimes wont. I am pretty sure it’s just an engine bug without a solution.

No, this is pretty intentional. The server only replicates playback but it can’t play sounds because it doesn’t have an AOD, so there are a limited number of spaces where it’s allowed to play sounds in (e.g. Workspace). Clients handle the actual sound playing for themselves.

If you asked me, I’d say that it would be best to make the sound system local. It’s probably server-sided for the sake of being able to modify the queue and to synchronise the current audio across all clients but those features aren’t too important. In a client-managed soundtrack system:

  • You can add configurations for sound, such as volume or muting, that the client may want to take advantage of. Well, this can still be done if it was on the server anyway.

  • For the case of paying to add tracks to the system, the server would just send the requested id to all clients and they could queue it up as the next track themselves either via prioritisation of requested ids or reorganising the queue. Former is probably easier to handle.

  • Synchronisation isn’t a must-have feature.

In any case: if you’re still running with hellish’s code, quick comment there. The very bottom of the code unnecessarily uses an anonymous function for the connection. That should be fixed to directly pass the play function. You can rewrite it as the following:

sound.Ended:Connect(Play)
1 Like