Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you prevent the huge lag spike when songs change?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Whenever I start a new audio for the first time, there's a large lag spike. My entire screen freezes for a few seconds.

I tried preloading the sounds, but it did not makes a difference.

I was wondering if there was any way to prevent this lag. I will not post my code, because it works fine, all I need to know is if this is possible, and if so how to do it.

0
I'm not too sure, I think it has to do with a Audio's Length, because, I used a 15-second long Audio, and it didn't lag for very long, but when I used a 1-minute long one, it lagged for more than 5+ seconds, so, there's nothing we can really do about it sadly. :/ TheeDeathCaster 2368 — 10y

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

This is actually quite simple to do! Roblox implemented some API in order to Preload assets, like sounds and images, so that it doesn't have to in the future (why you get the lag spikes).

local ContentProvider = Game:GetService("ContentProvider")

local assetList = {} -- I suggest creating a table of asset ids (Ex: 130758889)

for _, assetId in pairs(assetList) do
    ContentProvider:Preload("http://www.roblox.com/asset/?id=" .. assetId)
end
0
Read his second paragraph. I know from experience that preloading the sounds doesn't stop the lagspike when they start playing. adark 5487 — 10y
0
Yeah unfortunately preloading doesn't work. Perci1 4988 — 10y
0
Sorry, I missed that part BlackJPI 2658 — 10y
Ad

Answer this question