【问题标题】:My Roblox Script doesn't change the model based on time (Roblox)我的 Roblox 脚本不会根据时间更改模型 (Roblox)
【发布时间】:2018-06-09 12:03:44
【问题描述】:

我正在开发一种自动路灯,它应该会根据时间而改变。这是代码:

--------------------------------------------
-----------Street Light Script!-------------
-----------Made by multiplemark-------------
--------------------------------------------
local ControlledByGameTime = true -- Setting to true makes it so that the lights 
activate only during the selected time.
local TurnLightsOnAt = 20 * 60 -- Turns lights on at 8 P.M. by default.
local TurnLightsOffAt = 8 * 60 -- Turns lights off at 8 A.M. by default.
local Lights = script.Parent.PointLight.Enabled
local LightBlock = script.Parent
if ControlledByGameTime == true then
    while true do
        local CurrentTime = game.Lighting:GetMinutesAfterMidnight()
        if CurrentTime >= TurnLightsOffAt then 
            Lights = false
            LightBlock.Material = "SmoothPlastic"
            LightBlock.Brick = 163,162,165
        end
        if CurrentTime >= TurnLightsOnAt then
            Lights = true
            LightBlock.Material = "Neon"
            LightBlock.Brick = 255,255,0
        end
    end
else
    Lights = true
    LightBlock.Material = "Neon"
    LightBlock.Color = 255,255,0
end

它应该做的是检查时间,如果它符合定义的要求,则更改模型的材质和颜色,并启用/禁用 PointLight。

【问题讨论】:

    标签: roblox


    【解决方案1】:

    我认为问题在于您的 if 语句。在评估是否是上午 8 点之后,您正在评估是否在晚上 8 点之后。由于晚上 8 点(或 24 小时格式的 20)在上午 8 点(或 8 24 小时格式)之后,如果一个值大于晚上 8 点,它也大于上午 8 点。

    你可以做的只是有一个等于语句而不是一个大于。所以像:

    if (time==TURNOFFLIGHTS)
        turnofflights ();
    
    else if (time==TURNONLIGHTS)
        turnonlights ();
    

    这样,它只会在夜晚开始的特定时刻关闭灯,并且仅在白天开始的那一刻打开它们。

    【讨论】:

      猜你喜欢
      • 2020-06-23
      • 2018-12-28
      • 2023-01-26
      • 2020-12-10
      • 2018-06-17
      • 1970-01-01
      • 2020-09-11
      • 2021-09-28
      • 1970-01-01
      相关资源
      最近更新 更多