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

How do I fix this cooldown problem that when you press K it doesn't get the debounce?

Asked by 2 years ago

Ok, so I'm trying to add a cooldown to my gui that when you press k the gui opens with a smooth animation and you have to wait until the cool down that is 6 seconds long but it, went wrong, and then, something went wrong in the output and you still can spam the gui to open.

The code:

local Plr = game.Players.LocalPlayer
local mainframe = script.Parent


local debounce = false
Plr:GetMouse().KeyDown:Connect(function(K)
    if not debounce then
        debounce = true
    end
    if K == "k" then
        local object = script.Parent
        object.Position = UDim2.new(0.183, 0,0.999, 0)

        wait(0.1)

        object:TweenPosition(UDim2.new(0.183, 0,0.875, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint)

        wait(6)
        debounce = false
    end
end)

1 answer

Log in to vote
0
Answered by
W0_0SH 65
2 years ago
Edited 2 years ago

Try doing the debounce like this. Also I recommend you use UserInputService rather than Player:GetMouse().

local Plr = game.Players.LocalPlayer
local mainframe = script.Parent


local debounce = false
Plr:GetMouse().KeyDown:Connect(function(K)
    if not debounce then
        debounce = true

    if K == "k" then
        local object = script.Parent
        object.Position = UDim2.new(0.183, 0,0.999, 0)

        wait(0.1)

        object:TweenPosition(UDim2.new(0.183, 0,0.875, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint)

        wait(6)
        debounce = false
    end
end)
0
Ok, I'm gonna try it. markuusik 2 — 2y
0
Thank you so much! markuusik 2 — 2y
0
No problem. W0_0SH 65 — 2y
Ad

Answer this question