Consumable entites

Hey guys. I’m new to the lua coding scene and I have a question about some code.

I’m running darkrp and I’ve put in cocaine shipments. Here is the code for the cocaine.


function ENT:Use( activator, caller )
	self:Remove()
	if ( activator:IsPlayer() ) then
		local health = activator:Health()
		activator:SetHealth( health + math.random(5,50))
	end
end

When i hit E on the cocaine it removes it but doesn’t give health and leaves a weird shadow.
The cocaine on the left is before i use it and the shadow on the right is afterwards without health gain.

Any help? Thanks

http://cloud-4.steampowered.com/ugc/594785681560145636/D915A747882772DBA08F02EFA7AE93FBC5FBF141/

Move the self:Remove() to the bottom of the use function, and test that. It’s being removed before the rest of it can run.

My code now looks like this but still does the same thing. :suicide:


function ENT:Use( activator, caller )
	if ( activator:IsPlayer() ) then
		local health = activator:Health()
		activator:SetHealth( health + math.random(5,50))
	end
	self:Remove()
end

Entity activator

The initial cause for the input getting triggered.

Entity caller

The entity that directly triggered the input.

Use caller:IsPlayer() and caller:SetHealth