✓ Accepted answer
#What you did wrong
You're trying to revive a dead body whose body parts are separated so they instantly die. Instead, you can clone the NPC while they're alive and use that clone instead and delete the dead body. Also, you should never use an if statement in this case. Use the Died event.
#Clone
Clone is self-explanatory. It copies any object but you must set it's parent to something or its parent will be nil.
print(Part:Clone().Parent)
local A = Part:Clone()
A.Parent = workspace
print(A.Parent)
nil
game.Workspace
#Destroy
Many people use remove, I used to use remove but I stopped because remove doesn't actually delete the object they just change the parent to nil, so it still exists in the game but it's not interactive.
local Part = workspace.Part
Part:remove()
Part.Parent = workspace
#Died event
It fires every time a humanoid health reaches 0 or below. This is also a tip in Scripting Helpers' "Tip of the Day". It should be used for functions done upon a death.
Humanoid.Died:connect(function()
print(Humanoid.Parent.." has died!")
end)
Player1 has died!
#Final Product
local dummy = script.Parent
local dummy2 = dummy:clone()
local humanoid = backup:FindFirstChild("Humanoid")
local RespawnTime = 5
if humanoid then
humanoid.Died:connect(function()
wait(RespawnTime)
dummy:Destroy()
dummy2.Parent = workspace
dummy2:MakeJoints()
end)
end
Hope it helps!
4 comments
Once the bonds/welds are broken there's no way to reattach them in a short manner.
So that means I would have to clone to dummy?
I edited my code.
Nice catch, I didn't spot that.