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

Why is the bot respawning with 0 Health?

I made a respawn script for a mob that I made but everytime I set the health back to 100 it just keeps 0... why is that? Here is the script

name="Humanoid"
local maxhealth = 100
local load = script.Parent.Humanoid:LoadAnimation(script.Parent.Idle)
load:Play()
script.Parent.Humanoid.Changed:Connect(function()
	if script.Parent.Humanoid.Health < 1 and script.Parent.Dead.Value == false then
		script.Parent.Dead.Value = true
		
		for i,v in pairs(script.Parent:GetChildren()) do
			if v:IsA("MeshPart") then
				for i = 1,10 do
					wait(.05)
					v.Transparency = v.Transparency + 0.1
				end
				
			end
		end
		
		
		print("Bot died")

		wait(5)
		
		
		
		
		for i,v in pairs(script.Parent:GetChildren()) do
			if v:IsA("MeshPart") then
				v.Transparency = 0

			end
		end
		
		script.Parent.Humanoid.Health = maxhealth -- Over here I set it back
		wait(1)
		script.Parent.Dead.Value = false
	end


end)

1 comment

1 answer

✓ Accepted answer

It's maybe because the humanoid when dead, stays dead, I think that's because when it dies, it turns into a different instance called a DeadStateHumanoid or something. Try deleting the humanoid and adding a new one, you can even make variables to copy the old data to the new one.

Hope this helps :3

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