Disabling flashlight

I have been trying to make my own flashlight script, though there are already many out there, I just wanted to try it on my own. It hasn’t worked out, and I have tried to just take baby steps and try disabling the flashlight and I can’t even manage to do that. Here is what I did and the error I get with it


function disablingflashlight()
    ply:AllowFlashlight(false)
end

hook.Add("Think","Disable ze flashlight", disablingflashlight)

error


[ERROR] RunString:5: attempt to index global 'ply' (a nil value)
  1. fn - RunString:5
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


And yes I run it serverside… Any ideas?

[editline]20th February 2015[/editline]

and I have also tried to do LocalPlayer():AllowFlashlight(false) and Player:AllowFlashlight(false)

Use the PlayerInitialSpawn hook with ply:AllowFlashlight( false ). Putting it in a think hook is:

  1. Impossible since ply isn’t provided in the function
  2. Inefficient since you need to only call the function once

Make sure you run it serverside since AllowFlashlight doesn’t work clientside.

You didnt set the variable ply.

Its bad hooking it to think, pointless lag