Entity respawn

Hey, I need some help on making an entity I made respawn back to the exact same position it was destroyed in, for now I made it spawn back just to one set position using getpos but I need more than one in the map at the same time.


function ENT:OnTakeDamage(dmg)
	if self.burningup then return end

	self:SetNWInt("health", self:GetNWInt("health")-dmg:GetDamage())
	if self:GetNWInt("Health") <= 0 then
		local rnd = math.random(1, 10)
		if rnd < 3 then
			self:SetNWInt("health",500)
		else
			self:Remove()
			timer.Simple(10,function ()
            local respawnz = ents.Create("morphine")
            respawnz:SetPos(Vector(-1671.330811 ,105.346115 ,-105.968750))
            respawnz:Spawn()
            

			end)
		end
	end
end

I would make morphine spawner entities that handle this.

Why don’t you just use

Entity:GetPos? Do you need it to be saved?

I tried putting the respawn:SetPos do entity:getpos but it doesn’t work, it never gets spawned again after being destroyed if I do that. I could make 3 separate entities and just change their vector but that’s the tedious part.



	if self:GetNWInt("Health") <= 0 then


make that ‘H’ lowercase. it should work. you can’t use self:GetPos() because that ‘self’ is already removed. if you want random positions for morphines then you may want to make a table including all of those spawnpoints and random from that table. Also after spawning morphine entity, I suggest activating it with respawnz:Activate()

if you want it to respawn in exact same position; place timer before self:Remove() and set pos, ang of ‘respawnz’ entity. Then you can spawn&activate it.

heres how to do it;


   
                ...
		else
                        local respawnz = ents.Create("morphine")
                        respawnz:SetPos(self:GetPos())
                        respawnz:SetAngles(self:GetAngles())

			timer.Simple(10,function()
                        respawnz:Spawn()
                        respawnz:Activate()
			end)

                        self:Remove()
		end
	end
end


Thanks a lot !