Roblox Studio 忽略了我的"If Statement"行

所以我有一个脚本,一直检查一个值。然而,即使这个值是 true,函数也根本不会运行。

我尝试添加 "wait()" 来解决问题,但那根本没用。

useless = 0
wait(1)
repeat
    print("watno")
    wait()
    if script.Parent.Parent.Parent.windowsopen.Value == true then
        wait()
        for i = 5.5,0,0.1 do
            print("wat")
            wait()
            useless = useless + i
            script.Parent.Size = Vector3.new(script.Parent.Size.X, script.Parent.Y - 0.1, script.Parent.Size.Z )

        end
    elseif script.Parent.Parent.Parent.windowsopen.Value == false then

        wait()
    end
until false

"windowsopen" 的值始终为 true,但它从未运行过。

点赞
用户4070330
用户4070330

您最有可能由您的 for 循环引起的问题,您应该将其更改为

      for i = 55, 0, -1 do
            print("wait")
            wait()
            useless = useless + 0.1*i
            script.Parent.Size = Vector3.new(script.Parent.Size.X, script.Parent.Y - 0.1, script.Parent.Size.Z )
        end

因为(a)如果您想在循环中减少 i,则第三个参数应该为负数,(b)您确实不应该在 for 循环中使用 floatdouble,因为精度\表示:0.1 可能最终被表示为 0.1000000000000001(或类似的东西),并且在 i 在循环中最终不会等于零。有关更多信息,请查看 Lua 用于表示 double 的格式(我认为是 IEEE 754,但我可能错了),您也可以查看 https://floating-point-gui.de/

2019-07-12 09:17:21