Sounds creating lag?

Hello,

My game (a shooter) currently has a rampaging issue with high amounts of lag making it unplayable after 10 minutes when there’s 5 or more players.

Microprofiler reports its “Sound” related, but I’ve done my biggest efforts to optimize how sound is played and yet the issue still remains.

I need to know what could be causing the issue, any advise would be greatly taken!

Game: ET [II] - Roblox
Sound

1 Like

There must be duplications of sound when firing without destroying them after. Sounds do take up a lot of memory so it would definitely make the game laggy

Just checked firing sounds don’t seem to be duplicating and ARE destroying properly.

Do you think OGG sound files may have to do something with this?

The type of file shouldn’t affect you, how are you destroying the sounds?

They all get added to a Garbage Collector. (GC)
I keep checking Workspace and I see no duplicated sounds or anything even with multiple clients.

local function CheckForGC()
	local Index = #Garbages - -1
	while true do
		if Index % 15 == 0 then
			RunService.Heartbeat:Wait()
		end
		local Table = Garbages[Index]
		if Table then
			local Sound = Table[1]
			local CanRemove = false
			if not CanRemove then
				if Sound then
					if not Sound.Parent then
						CanRemove = true
					end
				else
					CanRemove = true
				end
			end
			if not CanRemove then
				if not Sound.Playing then
					CanRemove = true
				end
			end
			if not CanRemove then
				if Sound.SoundId == "" then
					CanRemove = true
				end
			end
			if CanRemove then
				if Sound then
					Sound:Destroy()
				end
				table.remove(Garbages, Index)
			end
			if 0 <= -1 then
				if Index >= 1 then
					break
				end
			elseif 1 < Index then
			else
				break
			end
			Index = Index + -1
		else
			break
		end
	end
end

coroutine.wrap(function()
	while true do
		Thread:Wait(1)
		CheckForGC()
	end
end)

Sorry if I don’t seem to be giving you the answer you need, I’m not the one that handles all these problems but it has gotten to the point where I have to take responsibility.

Instead of adding it to that try doing this code after you play the sound and tell me if the lag still happens

game:GetService("Debris"):AddItem(sound,sound.TimeLength)

You might want to check if you’re making more sounds than should be deleted.

Also from a roblox update I believe the sound permission causes permanment lag in the game if you delete a sound before the server loads it. It happens in my game when I delete 1k audio sounds in the game before the server loads. Just putting that out as a possiblity if you’re completely certain it’s not your game.

It started happening out of no where so I kinda think this is the problem.

Nothing helped any other ideas?

Try to make a module script storing all the sound IDs, then have it so another script can use that sound id when creating a new sound. That way, you don’t have to store pre-loaded sound instances (Where most memory is consumed from) and you can just use ids to put into the created sound files, then delete them afterward using Debris Service

Example:

local sounds = {}
sounds.gunFire = "rbxassetid://-id-"
return sounds

Sorry to bump this up but did you find a solution?

I’m starting to get 13ms of Sounds rendering in just 2-4 minutes, the highest I’ve seen is 20ms.

Yeah found the solution it was on my end.

The bullet whiz sound triggered so much it wasn’t deleting properly.
Whoops.

The fix should be for anyone else with sounds creating lag just check if your sounds are being constantly created fast, and check if they’re actually being deleted.