How to make a respawning system

i have thought of this and im trying to make it happen i have 2 problems that i am facing

  1. Tagged HumanoidRootPart in the Instance Tagger will still exist but it doesnt
  2. i cant detect if the npc dies or something

i need help fixing it and also if i can detect if the previous npc died then i can respawn a new one

2 Likes

Uh I’m confused, what are you trying to do?

i think he is working on an obby or something.

i am trying to make the npc respawn after they die but i have no clue of how they die or listen to it as an event

You can use the Humanoid.Died event with the NPC’s humanoid.

1 Like

still no luck :c i did that but when they die second time it doesnt respawn and it takes 10 seconds to respawn

In studio, go to Players, then in properties there are a option where you can set the time the players take to respawn. :wink: This should work

its an npc not a player any other suggestions?

local humanoid = script.Parent.Humanoid.Health

while wait() do
if humanoid <= 0 then
local npc = game.ServerStorage.NPC
npc:Clone().Parent = game.Workspace

This will check if the npc’s health reached 0 and if it does, it will clone a copy of it into the workspace. Make sure to put the copy in ServerStorage.

No need to do a while loop when Humanoid.Died exists.

Simply change that code to
-- Assuming the script is inside your NPC

local npc = script.Parent
local hum = npc:WaitForChild("Humanoid")
local copy = npc:Clone() -- credit to @RoBoPoJi for mentioning 

hum.Died:Connect(function() -- Connect
    local klone = copy:Clone()
    klone.Parent = workspace -- Clone and parent
end)

Your script clones the dead npc. The respawning should be done by cloning an npc model from serverstorage, like in @StarBoythehero123’s script. But yes, you are right, humanoid.died is better for this than checking health in a loop.

Also, @StarBoythehero123, in your script the value of the humanoid variable (which refers to the humanoid’s health) is only set once. So the check in the if statement will always have the same result. If you wanted to check the health in a loop, you should have the humanoid object set as the value of humanoid and do

if humanoid.Health == 0 then -- Humanoid.Health can't be smaller than 0, so it's not necessary to have <=.
    -- code here
end
1 Like

but if i make them separate that might be a bad method but ill atleast try

local NPC -- model path
local NPC_Clone = NPC:Clone()

NPC.Humanoid.Died:Connect(function()
	NPC:Destroy()
	wait(10)
	NPC_Clone.Parent = workspace
end)
2 Likes

this is frustrating i cloned it and moved it into the server but it didnt replicate to the client it is visible from the server but invisible to the client

here is the code

-- // services \\ --
local CollectionService = game:GetService("CollectionService")
local NPCRootParts = CollectionService:GetTagged("NPCRootParts")
local ServerStorage = game:GetService("ServerStorage")
local NPCFolder = ServerStorage.NPC
local StartingZone = NPCFolder.StartingZone
local Villager = StartingZone.Villager

-- Debounce
local DAMAGE_DEBOUNCE = false

-- loop through if touched then damage them
for _, NPCRootPart in pairs(NPCRootParts) do
	if NPCRootPart:IsA("Part") then
		local Humanoid = NPCRootPart.Parent.Humanoid
		if Humanoid then
			Humanoid.Died:Connect(function()
				Villager:Clone().Parent = workspace.MobHolder.StartingZone
				NPCRootPart.Parent:Destroy()
			end)
		end
	end
end
1 Like

i fixed it by separating scripts thank you for all your help thanks!