NPC does not clone again

Hi everyone, I made a script that clones an NPC after it dies, the problem is that after the clone dies, it doesn’t bring up another clone again.

The NPC is controlled by an ObjectValue, to reference it.

Local Script:

local TWS = game:GetService("TweenService")
local NPC = game.Players.LocalPlayer:WaitForChild("Objetos").NPC
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage.RemoteEvents:WaitForChild("CompañeroMuerto")
local Rig = ReplicatedStorage["Acompañante"]
local Bill = ReplicatedStorage.BillboardGui
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()



NPC.Value.Humanoid.Died:Connect(function()
	local barra = Bill:Clone()
	barra.Parent = NPC.Value.Head
	local move = TWS:Create(barra.Barra,TweenInfo.new(5),{Size = UDim2.fromScale(1,1)})
	move:Play()

	move.Completed:Wait()
	
	while task.wait(3) do
		if (NPC.Value.Torso.Position - Character.Torso.Position).Magnitude < 50 then
			if NPC.Value.Humanoid.Health == 0 then
				remote:FireServer(NPC)
			end
		end
	end
end)

Server Script:

local NPC = script.Parent
local remote = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("NPCDead")
local Rig = game:GetService("ReplicatedStorage")["Acompañante"]

remote.OnServerEvent:Connect(function(player,NPC)
	NPC.Value:Destroy()
	local Clone = Rig:Clone()
	Clone.Parent = workspace
	NPC.Value = Rig
end)

1 Like

all characters which contain a humanoid have their archivable property set to false as default, change the archivable property to true before cloning it

Hello, the archivable property is enabled, however, it does not work.

maybe its because ur creating the npc on the client? idk

NPC.Changed:Connect(function()
	NPC.Value.Humanoid.Died:Connect(function()
		local barra = Bill:Clone()
		barra.Parent = NPC.Value.Head
		local move = TWS:Create(barra.Barra,TweenInfo.new(5),{Size = UDim2.fromScale(1,1)})
		move:Play()
		
		move.Completed:Wait()
			
		while task.wait(3) do
			if (NPC.Value.Torso.Position - Character.Torso.Position).Magnitude < 50 then
				if NPC.Value.Humanoid.Health == 0 then
					remote:FireServer(NPC)
				end
			end
		end
	end)
end)

When the NPC dies, the Humanoid.Died event is dced so you have to reconnect it every time the NPC.Value is changed.

I have solved the problem, thank you for your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.