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

UI opens but doesn't close. What am I doing wrong? [SOLVED]

What have I done wrong in this LocalScript? It is supposed to open and close a GUI however, the UI only opens and does not close.

game:GetService("UserInputService").InputBegan:Connect(function(Input, IsTyping)
	local open = false
	local close = true
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.H then
		if open == false then
			OpenGive()
			open = true
			close = false
		elseif open == true then
			CloseGive()
			open = false
			close = true
		end
	end
end)

The OpenGive and CloseGive functions are just UDim2 Values and a statement that prints what is happening.

1 answer

✓ Accepted answer

This requires none of that and should work. (make sure the script is in the said UI, and that's is a local script but in general, it should work.)

function keyPressed(input)
	if input.KeyCode == Enum.KeyCode.M then
		if script.Parent.Visible = true then
			script.Parent.Visible = false
		elseif
			script.Parent.Visible =  false then
			script.Parent.Visible =  true
		end
	end
end

game:GetService("UserInputService").InputBegan:connect(keyPressed)

4 comments

0

p.s Just change the M to H I forgot about that, because I took it from a game I'm making but a lot was changed so I just forgot.

0

Sorry, I only just say this and thanks for your help, it worked!

0

saw*

0

I've marked your answer as the solution.

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