Create Auto Clicker

Hi there, I am creating a client side script for a auto clicker here is what I have so far for it



	if buried.Settings["mouse_spam"] and input.IsKeyDown(KEY_UP) then
	local timer.Create("spam", 0.1, 1, function () RunConsoleCommand("+attack")
	end


Line 1 is for the button and key
Line 2 is supposed to be the timer, but it keeps getting error.

[ERROR] lua/buried.lua:572: unexpected symbol near '.'

the term local is for making a variable not override non-localized variables (local being the deepest code instance such as a new file or inside a loop or if/then/else statement)
this way, all scripts can access a variable called HOWMANYCOOKS, but inside one of your scripts you can create a local HOWMANYCOOKS variable that doesn’t override the global one, and vice versa
it is good to make anything possible local, that way you don’t accidentally override someone else’s variables

timer.Create() is a function being called to perform code according to parameters
remove the word local, because it doesn’t make sense there


if buried.Settings["mouse_spam"] and input.IsKeyDown(KEY_UP) then
	RunConsoleCommand("+attack")
		timer.Simple(0.000000000000000000001, function() RunConsoleCommand("+attack") end)
end

Is that a question? I don’t know what you want from me.

[editline]3rd August 2015[/editline]

If it isn’t working because you don’t know what you’re doing: you need to alternate between +attack and -attack in order to have the button mash repeatedly.

scrap your everything and do this instead:



local isdown = false
hook.Add("Think","MouseSpam",function() if isdown then RunConsoleCommand("-attack") else RunConsoleCommand("+attack") end isdown = !isdown end)


See that works but, it dosen’t stop. I am having this as a option in a menu. So this is what I did with it.



if buried.Settings["mouse_spam"] and input.IsKeyDown(KEY_UP) then
	local isdown = false
	hook.Add("Think","MouseSpam",function() if isdown then RunConsoleCommand("-attack") else RunConsoleCommand("+attack") end isdown = !isdown end)
	end

Top line being directory to the button and key


local isdown = false
hook.Add("Think","MouseSpam",function() if buried.Settings["mouse_spam"] then if isdown  then RunConsoleCommand("-attack") else RunConsoleCommand("+attack") end isdown = !isdown end end)

It is continious, dosent stop to spam it. Also it dosent turn off when given the execute command