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

Getting amount of times a player clicked a Gui Button?

Asked by 6 years ago
Edited 6 years ago

Of course I can assign a variable that counts up every time a button is pressed. And that, was my attempt. But I realized that that is definitely not reliable at all.

local debounce = false;
local count = 0;

local function Func()
    if debounce then return end;

    debounce = true

    --Code Here

    wait()
    count = count + 1;
    debounce = false;
end;

Func();

The thing is that, I am creating, basically a shop gui. There are two buttons; Previous and Next. There are quite a lot of frames and every time I press either button, I want the frame to either move away from screen or into the screen. I have created it fully, but the thing is that I use Numbers to check whether a frame is in the screen or not. I realized that if a person spam clicks the button, the number vanishes, or better, it moves up and down very quickly. Thus, the frames do not follow the algorithm.

I also implemented Debounce but that does not work if a function is short and If I did not want it to wait at all.

I think the most reliable source would be boolean but I do not know how to implement that on the code. Is there a better technique? Or am i just using the debounce wrong?

Your help would be appreciated. I have not included my frame code but will if you would like for me to do so, I can.

[EDIT[ Sparkevin had suggested me to use IntValue but that did not work either.

0
Have you tried adding an IntValue within the Gui or script to keep track? sparkevin 36 — 6y
0
Sorry a bit confused. So your problem is that your debounce wont work? PoePoeCannon 519 — 6y
0
^ Yee LightYagamiTheKira 116 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Incrementing a variable every time they click the button is the correct way to do it. The problem is with the debounce, but you don't even need one for something as simple as increasing a number every time you click a button.

This would work without error in a localscript in a button:

local clicked = 0

script.Parent.MouseButton1Click:Connect(function()
    clicked = clicked + 1
    print("clicked " .. clicked .. " time(s)")
end)
Ad

Answer this question