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

How do I make a decent IF statement for the dsicribed scenario?

Asked by 5 years ago

I'm trying to make a decal shown only if all lights were turned off, otherwise its transparency should just stay 1.

local light1 = game.Workspace.BathRoomLight1.PointLight --Bathroom Checked
local light2 = game.Workspace.MyBedroom.WallLight1.Lightpart.PointLight --My room Checked
local light3 = game.Workspace.LightsM.Part8.PointLight -- Aunt's room Checked
local light4 = game.Workspace.KitchenLight1.LightPart.PointLight --Kitchen Checked
local light5 = game.Workspace.WallLightWater1.Lightpart.PointLight -- Wall Light Water Checked
local light6 = game.Workspace.WallLightTv1.Lightpart.PointLight -- TV Checked
local light7 = game.Workspace.WallLightPc1.Lightpart.PointLight -- PC Checked
local light8 = game.Workspace.Ceilinglight1.LightPart.PointLight -- Ceiling Checked
local light9 = game.Workspace.Light.LightPart.SurfaceLight -- ?? :) Checked
local d = game.Workspace.Display.Decal

local lights = {light1, light2, light3, light4, light5, light6, light7, light8, light9,

    --light1,
    --light2, ...  
}

function Evaluate()
    for i = 1, #lights do
        if lights[i].Enabled == false then
            --we don't do shit
        else
            break
        end
    end
    d.Transparency = 0
    --Show decal
print ("You can see me now")
end

for i = 1, #lights do
    lights[i].Changed:Connect(function()
       Evaluate()
print ("Triggered")
    end)
end

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You can change the Evaluate function to something similar to this:

local function Evaluate()
    local showDecal = true
    for i = 1, #lights do
        if lights[i].Enabled == true then
            showDecal = false
            break
        end
    end

    if showDecal then
        d.Transparency = 0
    else
        d.Transparency = 1
    end
end
0
thanks, that fixed half of it. Your way does show the decal only when all lights went out BUT it doesn't hide it when a light was turned on again. Think you can help me out one more time? aprilsfooled 29 — 5y
0
Edited above - you just need an else clause to turn it off if showDecal is false vector3_zero 1056 — 5y
0
Perfect, mate! Appreciate it, working smooth as a baby's you know what :) aprilsfooled 29 — 5y
Ad

Answer this question