Wont preload soundID

help somebody it wont load ANY sound.

local plr = game.Players.LocalPlayer
local char = plr.Character
local root = char:WaitForChild("HumanoidRootPart")
local ContentProvider = game:GetService("ContentProvider")

local id = "rbxassetid://1209600026" -- set id to audio you want

local play
local preload = Instance.new("Sound")
preload.SoundId = id

local t = {
	["walk"] = {2, 5} -- name = {start pos, length, [optional] location, [optional] properties}
	--[[ properties
	ie:
		Volume : 5,
		MaxDistance : 10000
	]]
}

ContentProvider:PreloadAsync({id}, function(content, status)
	if status == Enum.AssetFetchStatus.Success then
		play = function(n)
			spawn(function()
				local sound = Instance.new("Sound", #t[n] >= 3 and t[n][3] or game:GetService("Workspace"))
				if #t[n] == 4 then
					for i,v in pairs(t[n][4]) do
						sound[i] = v
					end
				end
				sound.SoundId = content
				sound:Play()
				wait(t[n][2] * sound.PlaybackSpeed)
				sound:Stop()
			end)
		end
	else
		warn("Error loading assets")
		print(content)
	end
end)
wait(1)
play("walk")
wait(1)
play("walk")

script by @JayzYeah32
Errors:
image

This is probably a network bug and this usually happens in everyone game, it’s something we don’t really look at though

i just searched and get some info, we can only preoload images ID but not sounds. We should preload instances instead.

ok i fixed it, bruh. btw ty for replying

No problem we are always here to help!

I noticed a slight error in my code:

ContentProvider:PreloadAsync({id}, function(content, status)

is supposed to be

ContentProvider:PreloadAsync({preload}, function(content, status)

I forgot to change what was being preloaded after I uploaded the code.
(Thanks for pointing this out)

1 Like