在 roblox 中刷新脚本

问题描述 投票:0回答:1

我正在为 roblox 的一场音乐会编写脚本。 ServerScriptService 中有一个脚本,用于控制所有音乐和灯光。我需要一个 GUI 重置按钮,它将从头开始启动这个脚本。

我做了这样的事情:

local button = script.Parent
local ServerScript = game:GetService("ServerScriptService")
local ScreenGui = game:GetService("StarterGui").ScreenGui


local function onButtonActivated()

    for _, sound in ipairs(workspace.Sounds:GetChildren()) do
        if sound:IsA("Sound") and sound.Playing then
            sound.Playing = false
        end
    end
    
    for _, scripts in ipairs(ServerScript.Sounds:GetChildren()) do
        if scripts.Enabled then 
            scripts.Enabled = false
            
        end
    end
    
end


button.MouseButton1Click:Connect(onButtonActivated)

我的代码确实停止了音乐和灯光,但是如果我再次调用脚本,它会从停止的地方继续播放,而不是从头开始。如何解决这个问题?

lua roblox roblox-studio
1个回答
0
投票

使用 sound:Play() 和 sound:Stop() 而不是使用 sound.Playing。

sound:Stop() 将声音重置到曲目的开头,而不是当前所在的位置。

您可以分别使用 :Resume() 和 :Pause() 在当前位置开始和停止。

声音类文档

© www.soinside.com 2019 - 2024. All rights reserved.