#I need help making a respawn system for my spawning system and idk how to track if my npc has died

1 messages · Page 1 of 1 (latest)

white moon
#

Title self explanatory.

#

I can send my spawning script tmrw

#

If needed

minor adder
#
npc.Humanoid.Died:Once(function()
    -- code
end)
#

this connection fires once and disconnects once the npc dies

#

npc is well the npc

white moon
minor adder
#

what

white moon
#

npc is always a different model

minor adder
#

so what's the issue

white moon
#

Hmm so where should I put it?

#

I've got a spawning function

minor adder
#

if you want to implement it easier you can put a script with the code into the dummy

white moon
minor adder
#

but if you want to do it the proper way you could put it in the spawn function

#

how are you spawning it then

white moon
minor adder
#

how are you spawning it

white moon
#

I'll send tmrw I'm not on my pc

minor adder
#

ok

gilded wadi
white moon
#

Yep

gilded wadi
#

if it is a rig then just do

GetPropertyChangeSignal()

#

and connect it into a function

#

check if the health of the humanoid is 0 or below

#

like this

workspace.Rig.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    
    if workspace.Rig.Humanoid.Health <= 0 then
        
        
        
    end
    
end)
minor adder
gilded wadi
#

wtf is once bro

minor adder
#

you've never heard of once?

#

it's important to disconnect unused connections

#

it's the main cause of memory leaks if i recall correctly

gilded wadi
#

OMG

#

ty bro

minor adder
#

no problem i guess

gilded wadi
#

idk how I have never heard of that

#

I HAVE BEEN SCRIPTING LUAU ALMOST EVERY DAY FOR A YEAR

minor adder
#

you can also manually disconnect connections incase you didn't know

gilded wadi
#

LIL OVER A YEAR ACUALLY

minor adder
#

personally i've been scripting for like 3-4 years

gilded wadi
#

man I still got ways to learn

gilded wadi
#

but luau since 2024

minor adder
white moon
#

Thanks guys! I got it working.

#

Could I also ask you if I could optimize anythingin this code?