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

Can someone help me with this keybind?

Asked by
sad_eyez 162
8 years ago

i'm trying to make a keybind for a phone gui I made and I want the phone to slide up when P is clicked then slide down when its clicked again, if someone can help me that'd be great, I tested it with it open and it slides down correctly, but it doesn't slide up

Code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Phone = script.Parent.PhoneMainFrame

Mouse.KeyDown:connect(function(key)
    key = string.lower(key)
    if string.byte(key) == "p" then
        Phone:TweenPosition(UDim2.new(1, -210,1, -400),"InOut", "Quad", .5, true)
    else
        Phone:TweenPosition(UDim2.new(1, -210,1, -50),"InOut", "Quad", .5, true)
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

So... I've found a fix to your script, you made an else statement, which means, when you press the letter "P" it slides down, and that "else" is wrong, because, that means:

Once you press "P" if the GUI doesn't slide down then, slide up.

That's what you meant in your previous code.

So, it's easy, I've done a little debounce keybind in the script. So when you press "P" it slides, and then waits 0.5 seconds, then if the users presses "P" again it does the slide up.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Phone = script.Parent.PhoneMainFrame
local Debounce = false

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "p" and not Debouncethen
        Debounce = true -- state the debounce to true.
         Phone:TweenPosition(UDim2.new(1, -210,1, -400),"InOut", "Quad", .5, true)
        wait(0.5)
        Debounce = false -- The user already did the slide down, state it up false.
    elseif Debounce then -- Checks if Debounce is false or true.
        Phone:TweenPosition(UDim2.new(1, -210,1, -50),"InOut", "Quad", .5, true)
    end 

end)
Ad

Answer this question