for loop problem

im trying to make a for loop that deletes all the timers that my tool created.
code:
[lua]function TOOL:LeftClick(Trace)
if not Trace.Entity:IsValid() then return false end
if (CLIENT) then return true end
local ent = Trace.Entity
local reps = self:GetClientNumber(“reps”)
local mindelay = self:GetClientNumber(“mindelay”)
local maxdelay = self:GetClientNumber(“maxdelay”)
local val = 0
local timername = “Timer”,tostring(val)
val=val+1
timer.Create(timername, 0.01, reps, function()
if not ent:IsValid() then timer.Destroy(“Timer”) end
timer.Adjust(“Timer”, math.Rand(mindelay,maxdelay), reps)
self:Effect(ent)
self:Twitch(ent)
self:Soundemitt(ent)
end)
end

function TOOL:RightClick()
for i=0,val do
timer.Destroy(“Timer”,tostring(i))
end
end[/lua]
It seems like the tool doesnt even create multiple timers, because when i click prop a it does stuff to it but when i click prop b, prop a stops doing stuff and prop b starts.
when i right click i get this error:


[addons\electroducer\lua\weapons\gmod_tool\stools\electroducer.lua:94] 'for' limit must be a number

Help!!
I can give you the whole code if you need to test something ingame

val on line 22 is nil whats not to understand? you need to give it a value

val is defined in the TOOL:LeftClick function

val is local, so do self.val

[LUA]for i=0,self:val do[/LUA]
like this?

[editline]22nd July 2011[/editline]

:frowning:

[lua]
–Line 8
self.val = 0

–RightClick function
function TOOL:RightClick()
if !self.val then self.val = 0 return false end
for i=0, self.val do
timer.Destroy(“Timer”,tostring(i))
end
end
[/lua]