Problem With Auto-Shoot Script

I know Auto-Shooting Luas exist already, but I thought it would be a great script for me to practice with. For some reason, it is not working. Any help please? Thanks in advance!

[lua]On = 1

function toggle()
if On == 1 then
On = 0
LocalPlayer():ChatPrint(“Auto-Shoot Disabled”)
elseif On == 0 then
On = 1
LocalPlayer():ChatPrint(“Auto-Shoot Enabled”)
end
end
concommand.Add(“Autoshoot_Toggle”, toggle)

function unattack()
RunConsoleCommand("-attack")
end

if On == 1 then
if (input.IsKeyDown( MOUSE_LEFT )) then
RunConsoleCommand("+attack")
timer.Simple(1.0, unattack)
end
end[/lua]

[editline]12:32PM[/editline]

I know the timer is set to 1. I’m just trying to get everything working before I change unimportant things.

Hook it to Think or something similar.

-Dumb-

Or don’t do that. No really, don’t do that.

Why on earth would you do that? You would be passing a nil value as the timer callback.

Yeah… For some reason I can’t really grasp the understanding of Think. I have absolutely no idea how to utilize it.

hooking into an event means that whatever you hooked into it gets called whenever the function you hooked into does. So if you hook a function to think, it gets called whenever think does.

OH! Thank you so much! That seems like a much better idea than a timer. Thank you.