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)