Player:GetActiveWeapon()

Hello,
I am trying to use Player:GetActiveWeapon() within my script.

The following function is part of my clientsided script and is included by cl_init.lua . It is also added to the list of AddCSLuaFile of my init.lua



local function DrawWeaponStats()
	local ply = LocalPlayer()
	local wep = ply:GetActiveWeapon()
	if(!wep.IsValid()) then return false end
	local plyammo = wep:GetAmmoCount( wep:GetPrimaryAmmoType() )
	draw.DrawText( plyammo ,"ScoreboardText",ScrW() - 250, ScrH() - 250, Color(255,0,0,255),TEXT_ALIGN_CENTER )
	
	return true
end
hook.Add("HUDPaint","HUD_DrawWeaponStats", DrawWeaponStats())


I am constantly getting the error that GetActiveWeapon is a null value, but I don’t see why.
I am looking forward to hearing suggestions.
Thanks in advance.

EDIT: Fixed the problem :slight_smile: Had to define LocalPlayer after all entities were loaded.