New GMOD update now gives error


[ERROR] gamemodes/bhop/gamemode/sh_timer.lua:26: Tried to use a NULL entity!
  1. SetGravity - [C]:-1
   2. SetCheckStyle - gamemodes/bhop/gamemode/sh_timer.lua:26
    3. Function - gamemodes/bhop/gamemode/cl_timer.lua:320
     4. unknown - lua/includes/modules/usermessage.lua:87


sh_timer


23 local CSt = {}
24 function gtimer.SetCheckStyle(ply,st)
25 	CSt[ply] = st
26 	ply:SetGravity(1)
27 end

cl_timer



318 usermessage.Hook( "SetStyle", function(umsg)
319	gtimer.style = umsg:ReadShort()
320	gtimer.SetCheckStyle(LocalPlayer(),gtimer.style)
321 end)

What’s wrong as soon as the newest update came I get this.

SetCheckStyle is probably being called before LocalPlayer() is valid.

Hmmm I dont think I tried it

It says [FiBzY|22|STEAM_0:1:48688711] Lua Error: so meaning its giving me the error

It would give an error as its NULL.


[ERROR] gamemodes/bhop/gamemode/sh_timer.lua:26: Tried to use a NULL entity!

LocalPlayer() is NOT valid when the client runs first time.
You have to wait a second or tick before you can use it.

So what can I use to fix it?

You can use a bool set in an InitPostEntity hook to only run stuff after everything is initialized.