ROBLOX - If语句无法在while循环中运行吗?

我遇到了一些非常奇怪的事情。最初我试图制作一个音乐脚本(更像是系统),它也有同样的问题。现在我已将其简化为一个简单的测试:

while true do
    if script.Parent.musicstate.Value == true then
        print("播放")
    elseif script.Parent.musicstate.Value == false then
        print("停止")
    end
    wait()
end

运行时,它将仅打印“停止”或仅打印“播放”。它打印的字符串将取决于布尔值在游戏启动时的值,即它不会根据当前值更改打印内容。感谢任何帮助!

运行的结构是SongScript:

enter image description here

点赞
用户10496478
用户10496478

永远不要制造这样一个无限循环以崩溃您的整个系统!有更有效率的做法。您的问题是因为脚本会自动断开连接以防止系统崩溃。

script.Parent.musicstate.Changed:Connect(function()
    if script.Parent.musicstate.Value == true then
        print("Play")
    elseif script.Parent.musicstate.Value == false then
        print("Stop")
    end
end)
2018-10-13 13:25:31