Elseif and if don't work

Hi, I have a problem, and it is that the script is not executed when pressing the key, it should do its function but it does not. try to change the elseif and if values ​​but it doesn’t work, the script only works if I change it manually with the mouse.

local Open = false
local buttonPressed = false
local UisTiempo = 0.8
local UserInputService = game:GetService("UserInputService")
local KeyClose = script.Parent.KeyClose

UserInputService.InputBegan:Connect(function(key)
	if (key.KeyCode.Name == keyText) then
		if not buttonPressed then
			if KeyClose.Value == false then
				if Open then
					Open = false
					buttonPressed = true
					script.Parent.Value = true
					wait(UisTiempo)
					buttonPressed = false
			elseif KeyClose.Value == true then
				Open = true
				buttonPressed = true
				script.Parent.Value = false
				wait(UisTiempo)
					buttonPressed = false
				end
			end
		end
	end
end)

The first if statement where you are saying Key.KeyCode.Name it should be Key.KeyCode instead.

you never closed this if statement
yes you added an extra end at the bottom but you didn’t put it in the right place

Ah, I did not put the complete script but it is ok in that part, the button is the “M”

Try adding a few prints, see what stops it