self:SetOwner(self.Owner) Help

I’m trying to make the entity remove itself once the owner has left the server.



function ENT:Initialize()
	self:SetModel("models/props_c17/consolebox03a.mdl")
	self:SetOwner(self.Owner)
end
	
function ENT:Think()
if (IsValid(self.Owner)==false) then
		self.Entity:Remove()
	end
end


You could try using the player disconnect hook instead:



function ENT:Initialize()
	self:SetModel("models/props_c17/consolebox03a.mdl")
	self:SetOwner(self.Owner)
end

hook.Add( 'PlayerDisconnected', self, function( ply )
    if self:GetOwner() == ply then
        self:Remove()
    end
end )


That would probably work (someone correct me if I’m wrong)

Also, it might not have worked in your original code because you were doing



self.Entity:Remove()


When self IS an entity already, so you don’t need the .Entity part
Also, how is:



self:SetOwner(self.Owner)


Meant to work? Are you defining self.Owner anywhere before calling that?

I didn’t define self.Owner and I didn’t know that I didn’t need self.Entity part

Thanks a lot