• Trying to get this function to run repeatedly
    3 replies, posted
I'm trying to get this code to run every ten seconds, but it will run the first time then not repeat viewz = 0; insanity = insanity or 0; function insane() for k, v in pairs(ents.FindInSphere( LocalPlayer():GetPos() + Vector(0,0,50), 200 )) do if (v:IsNPC()) then viewz = viewz + 1 print("+1") if viewz > 1 then insanity = insanity + viewz end end if insanity > 100 then insanity = 100 elseif insanity > 0 then insanity = insanity - 1 end if insanity == 100 then print("You are insane") print(insanity) elseif insanity >= 85 then print("You are almost insane") elseif insanity >= 50 then print("You are half insane") print(insanity) elseif insanity >= 25 then print("You are a quarter insane") print(insanity) else print("you are not going insane") print(insanity) end end end timer.Create("idelay", 10, 0, insane()) it produces this in console you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 you are not going insane 0 [ERROR] lua/insanity.lua:35: bad argument #4 to 'Create' (function expected, got no value)   1. Create - [C]:-1    2. unknown - lua/insanity.lua:35
what's on line 35?
You're passing the return of the `insane` function to timer.Create, you need to pass the `insane` function itself. That's why you're getting that error. timer.Create("idelay", 10, 0, insane)
thank you very much.
Sorry, you need to Log In to post a reply to this thread.