Playing multiple sounds at once without delays

Hello!

So I have a music system, which is basically 2 modules and a controller. One module contains a playlist and one module contains the authorized users who can execute commands and manage the songs. The controller basically mixes all of this and makes the sounds play.

Now let’s get to the problem:
The sounds are being played in parts (speakers) inside a folder. The controller takes a random ID, turns it into an instance (Sound), creates the instances in the parts (speakers) and plays them at the same time. The problem is that when the script plays all the sounds, some sounds are being played at different times, with a difference of a few ms. The code is a bit large, so if you need to see some parts of the code, I’m willing to send it to you.

I’m having some headache with this, if you can help me, I’ll be very grateful to you :wink:

2 Likes

Perhaps you can use ContentProvider:PreloadAsync() to load the sounds beforehand on the client so it would be able to play without having to load the sounds on the spot and delay the sounds.

2 Likes

Thanks for the reply.

So I tested your idea with this code:

local function preloadSound(songID)
	local sound = Instance.new("Sound")
	sound.SoundId = "rbxassetid://" .. songID

	local success, err = pcall(function()
		ContentProvider:PreloadAsync({sound})
	end)

	if success then
		log("Successfully preloaded sound: " .. sound.SoundId)
	else
		warn("[MUSICSYS] Failed to preload sound: " .. sound.SoundId .. " | Error: " .. tostring(err))
	end

	sound:Destroy() -- cleans the instance after being loaded
end

Unfortunately, it didn’t worked. Some sounds are still playing in different times.

1 Like

Could you show the part of the code that plays the sounds?

1 Like

The problem has been solved. If you have any doubts about the solution: Audio API. Thank you all for helping me!