calling function error

i have a money txt database and i want my hud to display the money amount but i cant get it to work

this is the funtion in my database.lua




function ply:getmoney()
  return  self:databaseGetValue( "money" )
end



that works fine when i print it like this in init.lua



function chatCommand( ply, text, public )
    if (string.sub(text, 1, 6) == "/money") 
        ply:ChatPrint("Your cash is: " .. ply:getmoney())
         return(false) 
    end
end
hook.Add( "PlayerSay", "chatCommand", chatCommand );


and i did include and AddCSLuaFile the cl_hud.lua

but when i try to make my hud display money amount it says "attempted to index local ‘ply’ a nil value



local ply = FindMetaTable("Player")
  
  
function hidehud(name)
     for k, v in pairs{"CHudHealth", "CHudBattery"} do
	      if name == v then return false end
		end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud)



  
function hud( ply ) 
local health = LocalPlayer():Health()
local money = ply:getmoney()
draw.RoundedBox(0, 5, ScrH() - 15 - 20, health, 15, Color(255,0,0,255))
draw.SimpleText(health, "default", 10, ScrH() - 15 - 40, Color(255,255,255,255))
draw.SimpleText(money, "default", 10, 20, Color(255,255,255,255))
end 
hook.Add("HUDPaint", "MyHudName", hud) 



not sure what i have done wrong

ps im just starting to learn lua hope you guys or girls can help

You really should name that variable to something better to avoid later confusion, but ply doesn’t refer to a player object in the HUDPaint hook, just change ply:getmoney() to LocalPlayer():getmoney(), and remove the function arguments from the hook, assuming database.lua is shared.