Push Button Mechanics

I need help!
Im trying to scrip a button but no matter what I try to do it does not work.

The button Has two events : MouseUp and MouseDown
The button has two animations : for making the button go up and down
The button should behave : when the mouse button is pressed the button should go down and when the mouse is released the button should go up.

From what I’ve tried the button seems to get stuck in the down position when i click too fast .

1 Like

This should help with the issue your having
Scripting Buttons Tutorial

Here is a quick script you can use.

code:

local button = script.Parent
local buttonDownAnimation = button:WaitForChild("ButtonDownAnimation")
local buttonUpAnimation = button:WaitForChild("ButtonUpAnimation")
local debounce = false

button.MouseButton1Down:Connect(function()
    if not debounce then
        debounce = true
        buttonDownAnimation:Play()
    end
end)

button.MouseButton1Up:Connect(function()
    if debounce then
        buttonUpAnimation:Play()
        debounce = false
    end
end)

thanks for replying. Ill try your code!

1 Like