Roblox Studio Lua if-оператор в цикле - PullRequest
0 голосов
/ 11 марта 2020

У меня есть игра Roblox в этой игре, время меняется с использованием кода на сайте разработчика Roblox ( robloxdev.com ). Я делаю дверь с двумя союзами, которые называются «открытыми» и «закрытыми». , Я хочу, чтобы дверь была открыта между 10 утра и 5 вечера. Однако дверь не открывается, и она даже не открывает печать, открывая / закрывая, когда это подходящее время.

Это мой текущий код Примечание: сценарий в той же модели (называется: Дверь) как два союза.

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

        script.Parent.Open.Transparency = 0
        script.Parent.Open.CanCollide = true
    else
        --Close the door
        print("close")
        script.Parent.Closed.Transparency = 0
        script.Parent.Closed.CanCollide = true

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

Спасибо за любую помощь.

1 Ответ

1 голос
/ 11 марта 2020

Вы должны добавить wait в то время как l oop.

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

        script.Parent.Open.Transparency = 0
        script.Parent.Open.CanCollide = true
    else
        --Close the door
        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) -- change this to whatever you want
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...