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

How to stop a button from being clicked more then once?

Asked by 10 years ago

Ok,I made script so when you press a button it fades and then in the last part I added a debounce so it can only be clicked once, but your still able to click it,why?

part = script.Parent
clicked = false
part.MouseButton1Click:connect(function()
---------------Debounce------------------
 if clicked == false--Checks if clicked is false(Which it should be,because it already been set false)
    then 
    clicked = true-- Since it false it will turn it true(so we know it's alread been clicked)
end

----------------Fade Out------------------
    for fo = 0,10 do
        wait(0.1)
        part.BackgroundTransparency = fo/10--You need to divide to get the precise number(Other way won't work)
        part.TextTransparency = fo/10
        if fo/10 ==1
            then
            clicked = false

        end 
    end

end)

1 answer

Log in to vote
1
Answered by 10 years ago

You need the debounce with the script

part = script.Parent
clicked = false
part.MouseButton1Click:connect(function()
----------------Fade Out------------------
if clicked == true then
    clicked = false
    for fo = 0,10 do
        wait(0.1)
        part.BackgroundTransparency = fo/10--You need to divide to get the precise number(Other way won't work)
    part.TextTransparency = fo/10
        if fo/10 ==1 then
            clicked = false
        end
    end
    end
end)

Ad

Answer this question