--Antiremoval

function onRemove(i)
	ra2 = ra
	la2 = la
	rl2 = rl
	ll2 = ll
	hd2 = hd
	if (wasUsed) then return end
	if (i:IsA("BasePart")) then
		if (i.Position.y < 0) then return end
		if (i == head) then
			head = i:clone()
			head.Parent = char
			head.BrickColor = bcolor
			head.Material = material
			hd = neck:clone()
			hd.Part0 = tors
			hd.Part1 = head
			hd.Parent = tors
			hum.Health = hum.MaxHealth
			hum.PlatformStand = true
		end
		if (i == tors) then
			tors = i:clone()
			tors.Parent = char
			tors.BrickColor = bcolor
			tors.Material = material
			hd = neck:clone()
			hd.Part0 = tors
			hd.Part1 = head
			hd.Parent = tors
			ra = rS:clone()
			ra.Part0 = tors
			ra.Part1 = rArm
			ra.Parent = tors
			la = lS:clone()
			la.Part0 = tors
			la.Part1 = lArm
			la.Parent = tors
			rl = rH:clone()
			rl.Part0 = tors
			rl.Part1 = rLeg
			rl.Parent = tors
			ll = lH:clone()
			ll.Part0 = tors
			ll.Part1 = lLeg
			ll.Parent = tors
			h = hum:clone()
			hum:remove()
			wait()
			h.Parent = char
			hum = h
			hum.Health = hum.MaxHealth
			hum.PlatformStand = true
			anim = char:findFirstChild("Animate")
			if (anim) then
				cl = anim:clone()
				anim:remove()
				wait()
				cl.Parent = char
				cl = nil
			end
			anim = char:findFirstChild("Sound")
			if (anim) then
				cl = anim:clone()
				anim:remove()
				wait()
				cl.Parent = char
				cl = nil
			end
			hum.Changed:connect(fullHealth)
			tors.ChildRemoved:connect(onRemove)
		end
		if (i == rArm) then
			rArm = i:clone()
			rArm.Parent = char
			rArm.Material = material
			rArm.BrickColor = bcolor
			ra = rS:clone()
			ra.Part0 = tors
			ra.Part1 = rArm
			ra.Parent = tors
		end
		if (i == lArm) then
			lArm = i:clone()
			lArm.Parent = char
			lArm.Material = material
			lArm.BrickColor = bcolor
			la = lS:clone()
			la.Part0 = tors
			la.Part1 = lArm
			la.Parent = tors
		end
		if (i == rLeg) then
			rLeg = i:clone()
			rLeg.Parent = char
			rLeg.Material = material
			rLeg.BrickColor = bcolor
			rl = rH:clone()
			rl.Part0 = tors
			rl.Part1 = rLeg
			rl.Parent = tors
		end
		if (i == lLeg) then
			lLeg = i:clone()
			lLeg.Parent = char
			lLeg.Material = material
			lLeg.BrickColor = bcolor
			ll = lH:clone()
			ll.Part0 = tors
			ll.Part1 = lLeg
			ll.Parent = tors
		end
	end
	if (i == ra) then
		if (rArm) then
			if (rArm.Parent == char) then
				rArm:remove()
			end
		end
	end
	if (i == la) then
		if (lArm) then
			if (lArm.Parent == char) then
				lArm:remove()
			end
		end
	end
	if (i == rl) then
		if (rLeg) then
			if (rLeg.Parent == char) then
				rLeg:remove()
			end
		end
	end
	if (i == ll) then
		if (lLeg) then
			if (lLeg.Parent == char) then
				lLeg:remove()
			end
		end
	end
	if (i == hd) then
		if (head) then
			if (head.Parent == char) then
				head:remove()
			end
		end
	end
	if (ra2 ~= ra or la2 ~= la or rl2 ~= rl or ll2 ~= ll or hd2 ~= hd) then
		anim = char:findFirstChild("Animate")
		if (anim) then
			cl = anim:clone()
			anim:remove()
			wait()
			cl.Parent = char
			cl = nil
		end
		--[[local ff = Instance.new("ForceField")
		ff.Parent = script.Parent
		wait(2)
		ff:remove()]]
	end
end

health = 0

function fullHealth()
	diff = health - hum.Health
	if (hum.Health < 20) then
		hum.Health = hum.MaxHealth
	end
	if (diff > 100) then
		hum.PlatformStand = true
	end
end

function onAdd(i)
	if (i:IsA("Explosion")) then
		local rad = i.BlastRadius * 1.5
		local dist = (i.Position - tors.Position).magnitude
		if (dist <= rad) then
			local ff = Instance.new("ForceField")
			ff.Parent = char
			wait(0.2)
			ff:remove()
		end
	else
		i.ChildAdded:connect(onAdd)
	end
end

function onAddRecursive(dir)
	if (dir == nil) then return end
	local a = dir:children()
	local b = 0
	for b = 1, #a do
		onAddRecursive(a[b])
		a[b].ChildAdded:connect(onAdd)
	end
end

hum.Changed:connect(fullHealth)
char.ChildRemoved:connect(onRemove)
tors.ChildRemoved:connect(onRemove)
onAddRecursive(workspace)
workspace.ChildAdded:connect(onAdd)
