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

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

Asked by 5 years ago

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

0
Are you using the mouse or userinput seith14 206 — 5y
0
mouse AndresaBrasileira 12 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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
)
Ad
Log in to vote
0
Answered by 5 years ago

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)

Answer this question