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)
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)
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.
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
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: