Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

while loop won't go through if statement even though it has the requirements??

Asked by 3 years ago

I'm trying to make it so that all lanterns turn on when the ClockTime is at 5 which is night time so I put an if statement around a while loop so it keeps checking if its night time yet and when its exactly 5, the while loop wont go through the if statement inside. its probably a really easy and clear to fix but I'm probably too blind to notice

If you want to know it's a server script in ServerScriptService

local lantern1 = game.Workspace.Lantern
local lantern2 = game.Workspace.Lantern2
local lantern3 = game.Workspace.Lantern3
local lantern4 = game.Workspace.Lantern4
local lantern5 = game.Workspace.Lantern5

local lightning = game:GetService("Lighting")

while true do
    wait(3)
    print("starting over")
    if lightning.ClockTime == 5 then
        print("gamer")

        for i,v in pairs (game.Workspace:GetDescendants()) do

            if v.Name == "Light" then

                if v:IsA("Part") then

                    if v.Parent == lantern1 or lantern2 or lantern3 or lantern4 or lantern5 then

                        v.Material = Enum.Material.Neon

                        v.Color = Color3.fromRGB(255, 196, 124)
                        print("Lanterns turned on!")
                    end
                end
            end
        end
    end

end

Answer this question