Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my dummy's humanoid not regen after being killed?

I want the health of my dummy to go back to full (100) 10 seconds after dying. Problem is, it is not regening at all? I can't seem to find the problem after staring at my computer for a while. The script is in the dummy

 dummy = script.Parent
Humanoid = dummy.Humanoid

function regenDummy()
	Humanoid.Health = 100
end

if Humanoid.Health == 0 then
	wait(10) regenDummy()
end

4 comments

0

Once the bonds/welds are broken there's no way to reattach them in a short manner.

0

So that means I would have to clone to dummy?

0

I edited my code.

0

Nice catch, I didn't spot that.

2 answers

✓ 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 is the 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() --Still exists
Part.Parent = workspace --If you set the parent again then it reappears

#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 --The dummy
local dummy2 = dummy:clone() --Back-up dummy
local humanoid = backup:FindFirstChild("Humanoid") --I use FindFirstChild in case the humanoid is missing
--Important Variables
local RespawnTime = 5 --5 is the default respawn time. You can change this back to 10.
--Respawn script

if humanoid then --Checks to see if the humanoid exists.
	humanoid.Died:connect(function() --Died event waits until the NPC dies
		wait(RespawnTime)
		dummy:Destroy() --Remove dead body
		dummy2.Parent = workspace --Spawn another dummy
		dummy2:MakeJoints() --So that the dummy doesn't die as soon as it spawns,
	end)
end


Hope it helps!

4 comments

0

The code did not work :( I tried to find a solution but couldn't

0

Hey, thanks for the help, it still had a problem but I was able to find a solution. The problem was in line 3 "backup" was underlined in blue. So I added a variable, backup = dummy. Thanks for your help once again :)

0

Wowza that was an AMAZING answer!

0

Thanks ;)

What you could do is store the dummy in ReplicatedStorage, then clone it out of there and place it into the workspace every 10 seconds. After something with a humanoid dies, it and the children within it are deleted. Meaning when the dummy dies, the script is deleted. Im not sure if this happens anymore, but you may notice that the "dummy" dies when it is moved from ReplicatedStorage to Workspace, this is due to the detachment of joints. A simple solution to this is to do

dummy:MakeJoints()

I hope this helped!

2 comments

0

But the problem with this is that when it respawns every single NPC will all respawn from the same spot and it can only be revived once.

0

That is because of your if statement instead of an event.

This discussion is preserved as it was. New answers, comments, and votes are closed.