You can write your topic however you want, but you need to answer these questions:
I want my NPC to respawn on death, But nothing seems to be working. I’ve just started scripting so I need help, I’ve tried many tutorials but I cant find any that work. If you could send me a script or video that would be very useful for future scripting.
1 Like
You’ll need to listen for the Humanoid.Died
event, so you can detect when the NPC is dead, then you can spawn it in again.
You will have to use Humanoid.Died
to check when the humanoid dies, as what @Syclya said.
local Humanoid = Character:WaitForChild("Humanoid")
local function respawn(humanoid)
local respawned = game:GetService("ReplicatedStorage").characters:FindFirstChild(humanoid.Parent.Name)
if respawned then
respawned.Parent = workspace
--relocate respawned humanoid
end
end
Humanoid.Died:Connect(function()
respawn(humanoid)
end)
would disconnect help to? better optimization
You won’t need to disconnect unless it double-fires. Otherwise, you should be good.
But, in that case, use this:
local connection = Humanoid.Died:Connect(function()
connection:Disconnect()
respawn(humanoid)
end)
No, since the ‘Died’ connection needs to remain connected in order for the NPC to respawn multiple times.