Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am trying to make an anti-autoclick but i'm confused on how to use tick()?

I have a game and when you click a button it gives you money but I don't want people to anuse it with autoclicker. I have tried many different things but this is the main one:

	bitbtn.MouseButton1Click:Connect(function()
		local anticlick = tick()
		if tick() - anticlick < 0.3 then
			print("Clicked: "..tick() - anticlick)
		elseif tick() - anticlick > 0.3 then
			print(tick() - anticlick)
			playerData.Bitcoins.Value = playerData.Bitcoins.Value + 5
			updateData()
		end
	end)

It just comes up with something along the lines of: Clicked: 1.6689300537109e-06 no matter how fast it is clicked ( I tested an auto clicker ) and i'm out of ideas so if someone could help me fix this or has a different method please answer or comment.

~Ki_ngPhantom

1 comment

0

use debouce

2 answers

✓ Accepted answer

You would check how quick they click. I would say humans can't click every millisecond. So, we could do this.

local last = 0
script.Parent.MouseButton1Click:Connect(function()
	if tick() - last <= 0.001 then --if the last click was less or equal to 1 millisecond
		print('Turn off your autoclicker!')
	else
		print('You clicked it! Yay!')
	end
	last = tick()
end)

So, what does this do? last is the seconds since the last click. tick provides the number of seconds and milliseconds from a date, not really important what that date is.

You also probably learned to use subtraction to see how many more a value is than another, so that is what I did.

Hope this helps!

i never really used tick() but i would do this.

clicked = false
bitbtn.MouseButton1Click:Connect(function()
   if clicked == false then
	clicked = true
	
	  playerData.Bitcoins.Value = playerData.Bitcoins.Value + 5
       updateData()
	wait(1)
	clicked = false
end
      
    
end)

this i basicly made it where on clicked then i would change the bool value to true and it cant be activated again until the bool value is false again. if that kind of makes since

This discussion is preserved as it was. New answers, comments, and votes are closed.