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

togglable GUI why so many parameters for yalls posts?

Asked by 5 years ago
function PressK(key)
    if (key == "k") then
        if (Frame.Visible == true) then
            Frame.Visible = false
        elseif (Frame.Visible == false) then
            Frame.Visible = true
        end
    end
end
mouse.KeyDown:connect(PressK)

just wanted to know whats wrong with this code

0
you are using keydown hiimgoodpack 2009 — 5y
0
Why are you wrapping your if statements in brackets? User#19524 175 — 5y
0
@incapaz It's just a habit. Nothing wrong with it. It's actually a pretty good one. Don't quote me on this but I believe it's actually proper. I'm not totally sure tho. oreoollie 649 — 5y
0
yes in lua and python wrapping it in brackets is proper but not needed but i fixed this problem Reset386143 2 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Dude you can just say Frame.Visible = not Frame.Visible instead of if's. Its way simpler trust me. Because it makes the value opposite of what it was before. Also just use UserInputService for keydown functions. They are very reliable and they work across PC and Console.

0
And mobile. User#19524 175 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Mouse.KeyDown is deprecated, and so is connect. The KeyDown could be your problem.

You should switch to ContextActionService or UserInputService to get user input. Personally, I’d prefer ContextActionService, mainly because you can bind actions to functions, make mobile exclusive buttons, and bind multiple keys to functions without if statements.

function toggleGui() --don’t include any parameters, as bind action doesn’t allow these.
    Frame.Visible = not Frame.Visible
end

game:GetService("ContextActionService"):BindAction(
    "Toggle", --name of action
    toggleGui, --function to bind
    true, --Make a mobile button
    Enum.KeyCode.K,
    Enum.KeyCode.E,
    Enum.KeyCode.F
) --you can just use one if you like, but i want 3

That’s how to use this awesome service. That’s also how to bind multiple keys. You can use just one as well, of course.

Answer this question