On PhysgunPickup for a certain entity.

ok, before i start i would like to let all of you know that i am a very very beginner coder and i dont know much. But i had set up a function for physgunpickup and used the physgunpickup hook.add but i realised shortly after that the function would be called whenever anyone tried to physgun anything rather than just the entity which i wanted it to be called on. I was wondering how i could set it up so that the function would only run when a plyer physgunned a certain entity rather than everything.

i know this is probably a simple fix but as i said, Im only a beginner coder in lua.

Thanks in advance


function physgunned(ply, moneyevent)
PrintMessage( HUD_PRINTCENTER, "The Case has been physgunned by " ..ply:Nick()..". Removing Case")
ents.FindByClass( "moneyevent" )[1]:Remove(moneyevent)
BroadcastLua("surface.PlaySound(\"sound/moneyevent/hitsound.wav\")")

end
hook.Add("PhysgunPickup", "whenpickedup", physgunned)

Just add an If statement to check if it’s the entity you want the code to run on when picked up.

can you please explain how i would do so?


 if ( !moneyevent:GetClass() == "moneyevent") then return end -- This checks if the entity is  moneyevent if it not it does not run the code below it. 

Place this underneath the line containing the function deceleration.