Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Elseif function isnt working?

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)

2 comments

0

What did it print out for line 10?

0

i dont see the point of the elseif, why not just use else?

2 answers

✓ Accepted answer
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

2 comments

0

Yes thank you!!!

0

Could you upvote the Answer please

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)

1 comment

0

codeblocks dude

This discussion is preserved as it was. New answers, comments, and votes are closed.