#for some unholy reason, my copy of roblox studio magically forgot what an elseif is

1 messages · Page 1 of 1 (latest)

solemn badge
#

i literally JUST started making the doors for the office, and for some reason the on/off switch (indicated by the active variable) doesn't work. After using breakpoints and teh watch window i came to the conclusion that the cooldown (cd) does not return to being false after being set to true. You can see this in the watch window ofcourse. On top of that, putting a breakpoint on the elseif statement does not work either, its almost as if the program is ignoring that line entirely. Im not really sure how is that even possible. I do also kinda have an hypotesis that the cd not being active might be the direct cause as of why the esleif is being ignored, but i've yet to prove that.

local RS = game:GetService("ReplicatedStorage")
local Remotes = RS:WaitForChild("Remotes")

local TS = game:GetService("TweenService")

local DoorActivationRemRight = Remotes:WaitForChild("DoorActivationR")
DoorActivationRemRight.OnServerEvent:Connect(function(plr, RightDoor, RDoorButton)
    local cd = false
    local active = false
    if active == false and cd == false then
        cd = true
        task.delay(0.2, function()
            cd = false
        end)
        active = true
        print(active)
        local RDoorTweenON = TS:Create(RightDoor, TweenInfo.new(0.5), {CFrame = RightDoor.CFrame * CFrame.new(0, 50, 0)})
        RDoorTweenON:Play()
    elseif active == true and cd == false then
        cd = true
        task.delay(0.2, function()
            cd = false
        end)
        active = false
        print(active)
        local RDoorTweenOFF = TS:Create(RightDoor, TweenInfo.new(0.5), {CFrame = RightDoor.CFrame * CFrame.new(0, -50, 0)})
        RDoorTweenOFF:Play()
    end
end)
#

update, apparently it now actually reads the off part (where the elseif is) due to me just separating both sides of the function in 2 separate if statements, what it does now is read BOTH if statements at once, and do them BOTH, resulting in the right door opening and closing at the same time

#

its like i pressed the button twice in a row

#

does my mouse just have a double click problem or something

#

oh btw here's vid

#

oh my god it crashed
🥀

#

wait shit i figured it out

#

what if i were to just use a boolvalue for cd

#

nevermind same thing

solemn badge
#

here's an MRE that i just attempted

local active = false
if active == false then
    active = true
    print(active)
elseif active == true then
    active = false
    print(active)
end
#

its never fucking false

#

WHY is it never false

cosmic linden
#

cuz ur defining it in the same block ur recalling it from
?

#

put it in a outer nest

solemn badge
#

wdym by that
the definition of the variable is outside of the if statement

cosmic linden
#

u just set it to false so if it made it true then the next u do that code it still is in the false if condition cuz u just set it to false

solemn badge
#

oooooooooh

#

oh my god it actually worked