Jump to content

Despawning next day

Recommended Posts

I am creating a character and one of his perks is that he summons a shadowcreature to follow him around and attack stuff with him. He is meant to despawn when the character dies and respawn after a period of time after coming back to life. However i have just noticed that the shadowcreature will stay spawned through the entire day including all the way through night but once it turns the light and become the next day... he despawns and i can't find the reason for it :/.


Here is my spawn follower function:

local function SpawnNightmarepet(player)
if player:HasTag("playerghost") then return false end
for k,v in pairs(player.components.leader.followers) do
if k.prefab=="nightmarepet" then return false

local pos = Vector3(player.Transform:GetWorldPosition())
local offset = (FindWalkableOffset(pos,math.random()*PI*2,0.5,false))
if offset == nil then
if player.components.talker then
player.components.talker:Say("No Space!", 2.5)
local unit=SpawnPrefab("nightmarepet")
unit.Transform:SetPosition (pos:Get())

local brain = require("brains/abigailbrain")


master_postinit function with stuff relating to the follower:

inst.OnDespawn = OnSave

inst.OnSave = OnSave
inst:DoTaskInTime(0, function(inst) SpawnNightmarepet(inst) end)


The event listener function: 

inst:ListenForEvent("respawnfromghost", function(inst) inst:DoTaskInTime(10, function(inst) SpawnNightmarepet(inst) end) end)


That is all in my character prefab while this is in my nightmarepet prefab:


function(inst) print("stopsfollowing")
if not inst.components.health:IsDead() then inst.components.health:Kill() print("dies") print(inst.components.health.currenthealth)


I was wondering if someone happens to know what is wrong and a way to fix it so it doesn't despawn unless i die or leave a server

Edited by codelyoko373
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...