You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Roblox Luau游戏内音频资源加载失败,Studio中运行正常

Roblox游戏加载音频资源失败问题排查与解决需求

我在制作Roblox游戏时,尝试实现游戏加载时自动播放音乐,但实际游戏环境中该音频资源大多无法加载。通过ContentProvider:PreloadAsync()可验证此问题,测试代码如下:

local Attempt = true

while Attempt do
    ContentProvider:PreloadAsync({DayTheme},function(assetId,assetFetch)
        print("Got DayTheme with asset ID",assetId)
        if assetFetch == Enum.AssetFetchStatus.None then
            warn("DayTheme returned no valid information, and the engine didn't attempt to load it.")
        elseif assetFetch == Enum.AssetFetchStatus.Failure then
            warn("DayTheme failed to load and was aborted by the engine.")
        elseif assetFetch == Enum.AssetFetchStatus.Loading then return 
        elseif assetFetch == Enum.AssetFetchStatus.TimedOut then
            print("Load timed out, trying again.")
        else
            print("ContentProvider returned OK")
            if not DayTheme.IsLoaded then
                print("Waiting for DayTheme to load")
                local pass = 1
                repeat
                    task.wait(1)
                    pass = pass + 1
                    print(pass)
                until DayTheme.IsLoaded or pass == 10
                if not DayTheme.IsLoaded then warn("DayTheme failed to load") else
                    if not DayTheme.IsPlaying then print("Playing"); DayTheme:Play() end
                end
            else
                if not DayTheme.IsPlaying then print("Playing"); DayTheme:Play() end
            end
            Attempt = false
        end
    end)
    task.wait(3)
end

其中DayTheme是Sound实例(而非资源ID),运行这段代码时会出现两种失败情况:要么触发Enum.AssetFetchStatus.Failure对应的警告,要么在ContentProvider返回Enum.AssetFetchStatus.Success后,因DayTheme.IsLoaded检查不通过触发自定义警告。由于2017年起Roblox取消了资源自动重试加载机制,我用while循环实现了重试逻辑。

需要说明的是,这并非常见的「Failed to download asset」报错,游戏本身不会抛出明确错误,若没有上述代码,只会发现音乐始终不播放。目前不清楚资源预加载失败的原因,也不知道如何让它成功加载(或优化这类循环重试逻辑),导致游戏无法正常播放音乐。

其他注意事项

  • 音频资源源自ReplicatedStorage,会被:Clone()到Workspace的文件夹中,已做多重检查确保实例非nil且存在;
  • 脚本为放置在StarterPlayerScripts的LocalScript,移至ReplicatedFirst后问题依旧;
  • 该音频在Studio中加载完全正常,仅在实际游戏中大概率失败,仅约1/20的概率能成功加载;
  • 音频资源归我所有,游戏拥有使用权限,不存在权限问题。

已尝试的解决方法

  • 程序化创建、克隆并修改Sound实例的资源ID;
  • 调整资源在游戏内的存放位置;
  • 通过ContentProvider:PreloadAsync()循环重试;

以上方法均未解决问题,最终都会触发自定义超时限制。

理想情况下,需通过LocalScript实现该功能,确保音乐为玩家端独立播放,而非服务器全局播放。

内容的提问来源于stack exchange,提问作者xTerrene

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 23:55:16