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

Elseif function isnt working?

Asked by 6 years ago

So, I'm currently working on opening a door but it isnt working. So yes it does open the doors but it doesnt close..

Heres my script

local openfrontdoors = script.Parent
local key = game.ReplicatedStorage.getKey:InvokeServer("getkey")
local checkdoor = game.ReplicatedStorage.checkdoor:InvokeServer("status",key)

openfrontdoors.MouseButton1Click:connect(function()
    if checkdoor == false then
        print(checkdoor)
        game.ReplicatedStorage.OpenDoors:FireServer("closefrontdoor",script.Parent.Parent.Parent,key)
elseif checkdoor == true then
print(checkdoor)
game.ReplicatedStorage.OpenDoors:FireServer("openfrontdoor",script.Parent.Parent.Parent,key)
end

end)
0
What did it print out for line 10? PenguinDevs 45 — 6y
0
i dont see the point of the elseif, why not just use else? theking48989987 2147 — 6y

2 answers

Log in to vote
0
Answered by
PolyyDev 214 Moderation Voter
6 years ago
local openfrontdoors = script.Parent

openfrontdoors.MouseButton1Click:connect(function()
    local key = game.ReplicatedStorage.getKey:InvokeServer("getkey")
    local checkdoor = game.ReplicatedStorage.checkdoor:InvokeServer("status",key)
    if checkdoor == false then
        print(checkdoor)
        game.ReplicatedStorage.OpenDoors:FireServer("closefrontdoor",script.Parent.Parent.Parent,key)
    elseif checkdoor == true then
        print(checkdoor)
        game.ReplicatedStorage.OpenDoors:FireServer("openfrontdoor",script.Parent.Parent.Parent,key)
    end
end)

This should work. You weren't redefining key and checkdoor every time you clicked so it was always the same value and it never changed. So this new version of the script redefines it every time you click so that the value is always updated.

Up vote and Accept if this helped

0
Yes thank you!!! TheSecondVal266 -1 — 6y
0
Could you upvote the Answer please PolyyDev 214 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Try this

local openfrontdoors = script.Parent local key = game.ReplicatedStorage.getKey:InvokeServer("getkey") local checkdoor = game.ReplicatedStorage.checkdoor:InvokeServer("status",key)

openfrontdoors.MouseButton1Click:connect(function() if checkdoor == false then print(checkdoor) game.ReplicatedStorage.OpenDoors:FireServer("closefrontdoor",script.Parent.Parent.Parent,key) else if checkdoor == true then print(checkdoor) game.ReplicatedStorage.OpenDoors:FireServer("openfrontdoor",script.Parent.Parent.Parent,key) end end end)

0
codeblocks dude PolyyDev 214 — 6y

Answer this question