Cops get money when destroying printers

I was wondering how i would make my printers give cops money when destroyed.


local team = TEAM_POLICE
local money = 500

hook.Add( "EntityTakeDamage", "printerDestroyReward", function( ent, _, ply, amount )
   local name = IsValid( ent ) and ent:GetClass()
   if ( not ( name == "money_printer" and IsValid( ply ) and ent:GetHealth() <= 0 and ply:Team() == team ) then return end
   ply:ChatPrint( "You earned " .. money .. " dollars for destroying a printer!" )
   ply:GiveMoney( money ) -- Not sure if this is the right function; not too familiar with DarkRP
end )