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.

01local light1 = game.Workspace.BathRoomLight1.PointLight --Bathroom Checked
02local light2 = game.Workspace.MyBedroom.WallLight1.Lightpart.PointLight --My room Checked
03local light3 = game.Workspace.LightsM.Part8.PointLight -- Aunt's room Checked
04local light4 = game.Workspace.KitchenLight1.LightPart.PointLight --Kitchen Checked
05local light5 = game.Workspace.WallLightWater1.Lightpart.PointLight -- Wall Light Water Checked
06local light6 = game.Workspace.WallLightTv1.Lightpart.PointLight -- TV Checked
07local light7 = game.Workspace.WallLightPc1.Lightpart.PointLight -- PC Checked
08local light8 = game.Workspace.Ceilinglight1.LightPart.PointLight -- Ceiling Checked
09local light9 = game.Workspace.Light.LightPart.SurfaceLight -- ?? :) Checked
10local d = game.Workspace.Display.Decal
11 
12local lights = {light1, light2, light3, light4, light5, light6, light7, light8, light9,
13 
14    --light1,
15    --light2, ... 
View all 36 lines...

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:

01local function Evaluate()
02    local showDecal = true
03    for i = 1, #lights do
04        if lights[i].Enabled == true then
05            showDecal = false
06            break
07        end
08    end
09 
10    if showDecal then
11        d.Transparency = 0
12    else
13        d.Transparency = 1
14    end
15end
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