How do I reset the number of clicks when the player press another button

local Click = 0

Button.MouseButton1Click:Connect(function()
	if Click < 2 then
		Click = Click + 1
	end
							
	if Click >= 2 then
		Click = 0
	end
end)

I have multiple buttons and I would like to know how to reset the number of clicks when they press another button

3 Likes

Could you go into some more detail to what you’re asking?

So I have two text buttons I want the player to click twice to activate the button. However if the person click on one of the buttons and click on the other one it activates without clicking twice

1 Like

Is the local script under one of the buttons or does it handle all the buttons? It may be easier to just create an IntValue which you change as that can be referenced from any script rather than a local variable within one script

1 Like

You would need to use a localscript that would detect if the player hit another button. You would need to get the mouse, or use game:getservice. You would use something like Instance.Name as well.

It is connected to a for ipair loop. I’m not sure how that is going to help. Do you mean like having IntValue for each of the buttons?

1 Like

I meant storing the value for Click in an IntValue

Ok what so what do i do with the IntValue. Isn’t it the same as using a variable.
Sorry if I sound dumb

Yep but it can be referenced in other scripts

But that’s not really my problem. The problem is when the person clicks on one of the buttons since I set the variable of number of clicks to 2, the number of clicks now is 1. If the person clicks on the other button then the number of clicks would be 2 but I dont want that. I want it so the player is forced to click twice for one of the buttons in order for an event to trigger. If the person clicks on another button the variable would reset

So if any other button other than the one that requires the double click, the ‘Click’ variable is set to 0?

I’ll give an example. In the shop there’s a button called buy. If I click on it then it will say Confirm?. If I click on another button it will activate without the confirmation

Is the script within the button itself or in like a frame?

neither its in a folder and all of the buttons are under another folder

You said you are getting all the buttons with an inpairs loop right?

yes it is a in pairs loopssssss

1 Like

Can you send that part of the script?

for _, Button in pairs(StarterGui.Buttons:GetChildren()) do
2 Likes

So you need a way to track which button is pressed and if another button different from the original button is pressed?

Yes is there a better way or doing this so the Click number resets