Money being added on prop removal (help needed)

Alright. I’m trying to make it so that when you remove a prop it adds you money depending on it’s mass… this is what I’ve got.

[lua]hook.Add(“EntityRemoved”, “RefundProps”, function(ent)
if(ent:GetVar(“Founder”) != nil) then
print(“well, i got this far”)
ply = ent:GetVar(“Founder”);
ply:SetNetworkedInt(“money”, ply:GetNetworkedInt(“money”) + ent:GetPhysicsObject():GetMass())
print(“i’m at the end lol”)
end
end)[/lua]

And it just doesn’t work… the prints don’t even get printed and I have absolutely no idea why , no error messages either. So could a lua genius help me out please? Thank you.

Try putting a print in before the if.

Still nothing…

the Var “Founder” is nil then which means the stuff doesn’t run.

But the hook is meant to run before an entity is removed , so technically i should still be getting a print because i’ve put it before the If statement. So as soon as a prop is removed i should be getting the print which i am not.

If you are setting vars on the ents, then consider setting this on them. entity:CallOnRemove(yourFunction)

Yes , but wouldn’t that be unable to get the mass of my entity seeing as it’s already gonna be deleted?

It does exactly the same thing as the hook you’re using, only on an ent by ent basis and it actually works.

so it’d be something like this?

[lua] prop:CallOnRemove(“refundme”, sellprops, prop) // there’s more after and before but you get the point

function sellprop(ent)
print(“well, i got this far”)
if(ent:GetVar(“Founder”) != nil) then
print(“well, i got this far2”)
ply = ent:GetVar(“Founder”);
ply:SetNetworkedInt(“money”, ply:GetNetworkedInt(“money”) + ent:GetPhysicsObject():GetMass())
print(“i’m at the end lol”)
end
end [/lua]

Yeah, but you don’t need the ‘, prop’, the first argument is always the relevant entity.

So what should it be?

what the hell’s a “:GetVar()” ?

Shouldn’t you also give money to the owner?

“OwnerObj” ?

Also, I think “:GetVar” returns an integer and not an entity?

the founder is the owner. This is the script that works , and GetVar gave me a table with the player , which is alright seeing as the props don’t need to save and when a player leaves his props get deleted.

[lua]function GM:PlayerSpawnedProp( ply, model, prop )
local physob = prop:GetPhysicsObject()
local propmass = physob:GetMass()
if( (ply:GetNWInt(“money”) - propmass) < 0 ) then
ply:ChatPrint(“You don’t have enough money.”)
prop:Remove()
return end;

prop:SetVar( "Founder", ply )
prop:CallOnRemove("refundme", sellprops, prop)
self.BaseClass:PlayerSpawnedProp( ply, model, prop )

local color = team.GetColor( ply:Team() )

// Set the color
prop:SetColor(color.r, color.g, color.b, color.a)
print(prop:GetVar("Founder"))
SetPropHealth(prop)

local cash = ply:GetNetworkedInt("money")
local physob = prop:GetPhysicsObject()
if physob then
	local propmass = physob:GetMass()
	print(propmass/4)
	if prop:GetModel() == "models/props_c17/lockers001a.mdl" then 
	local propmass = 200 else
	ply:SetNetworkedInt( "money" , cash - propmass /4 - 20)
	end 
	ply:GetNetworkedInt("money")

end end[/lua] so if anybody could show me a script or something that can at least give me an idea of what am i am supposed to do would be very helpful.

prop:CallOnRemove(“refundme”, sellprops)

Yea , i already tried that before , it does same thing as every other thing i’ve tried which is absolutely nothing.