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

How do I get a GUI to appear and disappear for everyone on the game?

I want it when I press "q" the GUI appears or disappears for everyone.

function PressQ(key)
	if (key == "p") then
		if (Open == false) then
			gui.Enabled = true
			atv.Parent = gui
			Open = true
		elseif (Open == true) then
			gui.Enabled = false
			atv.Parent = game.ReplicatedStorage
			Open = false
		end
	end
end
 end

2 comments

0

Are you using the mouse or userinput

0

mouse

2 answers

✓ Accepted answer

This is because you are using deprecated code and wrapping your if statements in brackets. Brackets are math exclusive. Lines 2-3 and 7 error due to this. Remove the brackets.

I see you attempted a KeyDown event. Don’t, it’s deprecated. Instead use the UserInputService or ContextActionService. I will use ContextActionService.

function toggleGui() -- don’t add parameters
    gui.Enabled = not gui.Enabled 
    -- You don’t need any if statements checking if open or closed! Look @ that!

end

game:GetService('ContextActionService'):BindAction(
    'GuiToggle',
    toggleGui,
    false, 
    Enum.KeyCode.Q --, 
 -- Enum.KeyCode.P -- you can put multiple keys
)

So, if you're using :GetMouse, that's deprecated. You need to use UserInputService. Something like this would work.

UIS = game:GetService("UserInputService")
UIS.InputBegin:Connect(function(k,gpe)
if not gpe and k.Keycode == Enum.KeyCode.q then -- gpe makes sure the player isn't typing
if Open == false then
gui.Enabled = true
atv.Parent = gui
Open = true
else
gui.Enabled = false
atv.Parent = game.ReplicatedStorage
Open = false
end
end
end
end)

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