timer bug?

Does anyone know why timers do things such as print in doubles? (Referring to Regular timers, but Simple timers do things in doubles once)

For example, I tell a timer to print “hai” in console every 10 seconds, but it goes like this:

—game starts, waiting for first “hai” to print—
—first 10 seconds have passed, prints to console: “hai”—
—waiting for the next “hai” to print—
—2 seconds after the first “hai” prints, it prints again to console: “hai”—

then it loops on and does it over and over again, and prints 1 messages every 10 and 12 seconds.

Does anybody know how to fix this?

I’ve tried making the timer print what I need then toggling it off and having a simple timer toggle it on again in 10 seconds when the timer is supposed to print again, but it prints double anyways.

You did something wrong in your code, timers work perfectly fine. You either have two timers going and don’t know it or have some really weird settings. Post your code if you want more help that’s the best I can do.

[lua]local notifications = {
“test1”,
“test2”,
“test3”
}

function sendnotify()
timer.Create(“Tips”, 10, 0, function()
for k,v in pairs( player.GetAll() ) do
for _, n in pairs( notifications ) do
v:ChatPrint( n )
end
end
end)
end
hook.Add( “Initialize”, “notify”, sendnotify )[/lua]

You’re using a for loop that is reading from the notifications table, so it will keep looping until it reads and chatprints all the entries in the notifications table.

Try this, it will randomly grab one of the notifications and only print one at a time.
[lua]
timer.Create(“Tips”, 10, 0, function()
local Notifications = {
“tip 1”,
“tip 2”,
“tip 3”
}
local Tip = table.Random(Notifications)
for k,v in pairs(player.GetAll()) do
v:ChatPrint(Tip)
end
end)
[/lua]

It still prints every 10, and 12 seconds.