#If Statement failing to fire even though conditions have been met

1 messages · Page 1 of 1 (latest)

heady scaffold
#

Hey I've had a little trouble with this code and my limited knowledge of lua is really starting to show hehe. Anyway the code doesn't fire even when the conditions are met (both Booleans where triggered through their own code and also manually while testing)

The code receives no errors and works perfectly when not inside the if statement however as soon as you put it into an if statement it decides that nope it doesnt want to work.

local door = workspace.DoorEntrance
local TweenService = game:GetService("TweenService")

local doorstatus = door.DoorStatus
local powerstatus = script.Parent.Parent.Parent.PowerControls.PanelOnePower
local openlight = script.Parent.OpenLight
local closelight = script.Parent.Parent.GateClose.CloseLight
local testlight = script.Parent.TestLight

local sound = door.Sound

local hinge1 = door.Door1.PrimaryPart
local hinge2 = door.Door2.PrimaryPart

local door1open = TweenInfo.new(15)
local door2open = TweenInfo.new(15)

-------------------------------------

local doorCFrame1 = TweenService:Create(hinge1, door1open, {
    CFrame = hinge1.CFrame * CFrame.Angles(0, math.rad(80),0)
})
local doorCFrame2 = TweenService:Create(hinge2, door2open, {
    CFrame = hinge2.CFrame * CFrame.Angles(0, math.rad(-80),0)
})

-------------------------------------

function open()
    --sound:Play()
    doorCFrame1:Play()
    doorCFrame2:Play()
    task.wait(15)
    openlight.Color = Color3.fromRGB(2, 107, 91)
    closelight.Color = Color3.fromRGB(69, 71, 80)
    doorstatus = true
end

-------------------------------------

function onClicked()
    print("Click Registered")
    --open()
    print(doorstatus,powerstatus)
    if doorstatus == false and powerstatus == true then
        open()
        print("Door Opening Function Called")

end

script.Parent.Button.ClickDetector.MouseClick:connect(onClicked)
heady scaffold
#

hehe I have spent so long looking at different variations of this if statement and I want to cry 😭

#

and I know its gonna be like one letter that fucks me over frr

steel crystal
#

u do realize that to get the value u need to do .Value

#

and youre checking if an instance equals to true which it will never be equals to because its an instance

heady scaffold
#

they are both bool values and no I did not realise that

#

Is there a different way to run an if statement like I have it now

#

where it will check the condition of two values

steel crystal
#

that is what will return either true or false for a boolvalue instance

heady scaffold
#

lemme tinker rq

#

So would that be say

if doorstatus.Value == false and powerstatus.Value == true then
    script.Parent.Button.ClickDetector.MouseClick:connect(onClicked)
    task.wait(15)
    print(doorstatus)
end
heady scaffold
#

yeah thats looking like it works thanks

#

I never knew that hehe