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