Hi everyone. I have a bunch of local sound files that I am using for my game (temporarily, because I don't want to waste Robux on sounds). However, I want to detect if the file exists or not before loading it, so just in case, I can load a backup file stored on Roblox servers.
Other info: I am testing within Studio. I am testing with a LocalScript. This is a locally stored file and is not on the Roblox website The error is
Failed to load sound rbxasset://Sound.mp3: Unable to download sound data
I have tried using pcall() to change the SoundID, but that didn't work (LocalScript below, Sound.mp3 doesn't exist, the LocalScript is parented to a TextButton, and the Sound is parented to the same TextButton)
local BrokenSoundButton = script.Parent local Sound = script.Parent.Sound function TryBrokenSound() pcall(PlayBrokenSound) end function PlayBrokenSound() Sound.SoundId = "rbxasset://Sound.mp3" Sound:Play() end BrokenSoundButton.MouseButton1Down:Connect(TryBrokenSound)
Edit: Answered my own question. You can use ContentProvider:PreloadAsync
with Instances (not link to instances, unlike what the developer hub says) to detect whether it exists or not.
Edit 2: I love Scripting Helpers moderation. Totally not absolute garbage
rbxassets are given IDs, not names , and your sound file name might not be the same as something uploaded to roblox.
However, roblox provides you with a way to search their database of already existing sounds on their website: https://www.roblox.com/develop/library?CatalogContext=2&SortAggregation=5&LegendExpanded=true&Category=9
You cannot use locally stored sound files. See https://developer.roblox.com/en-us/articles/Content for more information.
Closed as off-topic by SteamG00B, IAmNotTheReal_MePipe, Cynical_Innovation, and JesseSong
This question has been closed by our community as being off-topic from ROBLOX Lua Scripting.
Why was this question closed?