Codelyy Posted June 5, 2015 Share Posted June 5, 2015 (edited) 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 endfor k,v in pairs(player.components.leader.followers) doif k.prefab=="nightmarepet" then return falseendendlocal pos = Vector3(player.Transform:GetWorldPosition())local offset = (FindWalkableOffset(pos,math.random()*PI*2,0.5,false))if offset == nil thenif player.components.talker thenplayer.components.talker:Say("No Space!", 2.5)endreturnendpos=pos+offsetlocal unit=SpawnPrefab("nightmarepet")unit.Transform:SetPosition (pos:Get())unit:AddComponent("follower")player.components.leader:AddFollower(unit)unit.spawnedforplayer=playerlocal brain = require("brains/abigailbrain")unit:SetBrain(brain)end master_postinit function with stuff relating to the follower: inst.OnDespawn = OnSaveinst.OnSave = OnSaveinst: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: inst:ListenForEvent("stopfollowing",function(inst) print("stopsfollowing")if not inst.components.health:IsDead() then inst.components.health:Kill() print("dies") print(inst.components.health.currenthealth)endend) 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 June 5, 2015 by codelyoko373 Link to comment https://forums.kleientertainment.com/forums/topic/54843-despawning-next-day/ Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now