Roblox Studio Lua循环语句中的if语句

我在Roblox游戏中使用Roblox开发者网站 (robloxdev.com) 上的代码让时间改变。我正在制作一个由两个联合体组成的“开”和“关”的门。我希望这扇门在上午10点和下午5点之间打开。然而,门不会打开,甚至在正确的时间也没有打印开/关闭。

这是我的当前代码。注意:脚本与两个联合体在同一个模型中(称为: 门)。

while true do
   if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
        --打开门
        print("open")
        script.Parent.Closed.Transparency = 1
        script.Parent.Closed.CanCollide = false

        script.Parent.Open.Transparency = 0
        script.Parent.Open.CanCollide = true
    else
        --关闭门
        print("close")
        script.Parent.Closed.Transparency = 0
        script.Parent.Closed.CanCollide = true

        script.Parent.Open.Transparency = 1
        script.Parent.Open.CanCollide = false
    end
end

感谢任何帮助。

点赞
用户12839543
用户12839543

你应该在 while 循环中添加 wait。

while true do
   if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
        --打开门
        print("open")
        script.Parent.Closed.Transparency = 1
        script.Parent.Closed.CanCollide = false

        script.Parent.Open.Transparency = 0
        script.Parent.Open.CanCollide = true
    else
        --关闭门
        print("close")
        script.Parent.Closed.Transparency = 0
        script.Parent.Closed.CanCollide = true

        script.Parent.Open.Transparency = 1
        script.Parent.Open.CanCollide = false
    end
    wait(1) -- 将此更改为任何您想要的数值
end
2020-03-11 20:12:07