My script always goes to the second option of the else statements

I need help on helping to fix this area of code I made. For some reason, my line of code always chooses the second option of the “else” statement.
So basically, I need this guy to go away when the lights turn off. If you leave the lights on for too long, he kills you. but if you turn them off, he SHOULD go away. My problem is that he doesnt and kills you regardless of the value change.
1 = Lights On
0 = Lights Off

local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script:FindFirstChildOfClass(“Animation”))
local Spotted = workspace.Spotted
local Exposure = workspace.Rising
local LightLevel = workspace.LightLevel.Value
local random = workspace.FlumptyRandomizer
local allPlayers = game.Players:GetChildren()
local Flumptyfolder = workspace.FlumptyJumpscare
local function killEveryone()
end
anim.Looped = false

anim:GetMarkerReachedSignal(“SpotSound”):Connect(function()
print(“Flumpty Is Looking”)
Spotted:Play()
if LightLevel == 1 then
Exposure:Play()
anim:AdjustSpeed(0)
random.Disabled = true
wait(5)
if LightLevel == 0 then
anim:AdjustSpeed(1)
else
for i = 1, #allPlayers do – It is always going to this one regardless of Value changes.
Exposure:Stop()
Flumptyfolder.Scream:Play()
Flumptyfolder.ScreamMusic:Play()
allPlayers[i].Character.Humanoid.Health = 0
wait(2)
anim:AdjustSpeed(1)
workspace.FlumptyRandomizer.Disabled = false
end
end
else
anim:AdjustSpeed(1)
end
end
)

anim:Play()
anim.Stopped:wait()
wait(.1)
script.Parent:Destroy()
robloxapp-20211126-2223582.wmv (685.1 KB)

that video is useless dont look at it

This is the line that’s causing you the problem. You are basically making LightLevel the value of whatever LightLevel.Value is when the script is being read. Change it to

local LightLevel = workspace.LightLevel

and change your if statements to:

if LightLevel.Value == 0 then
1 Like

Thank you so much! It doesn’t go to the second option all the time anymore. Thanks!

1 Like