--]]



function getHumanoid(model)
	for _, v in pairs(model:GetChildren()) do
		if v:IsA'Humanoid' then
			return v
		end
	end
end


local zombie = script.Parent
local human = getHumanoid(zombie)
local hroot = zombie.HumanoidRootPart
local zspeed = hroot.Velocity.magnitude


local pfs = game:GetService("PathfindingService")

function GetPlayerNames()
	local players = game:GetService('Players'):GetChildren()
	local name = nil
	for _, v in pairs(players) do
		if v:IsA'Player' then
			name = tostring(v.Name)
		end
	end
	return name
end

spawn(function()
	while wait() do

	end
end)

function GetPlayersBodyParts(t)
	local torso = t
	if torso then
		local figure = torso.Parent
		for _, v in pairs(figure:GetChildren()) do
			if v:IsA'Part' then
				return v.Name
			end
		end
	else
		return "HumanoidRootPart"
	end
end

function GetTorso(part)
	local chars = game.Workspace:GetChildren()
	local torso = nil
	for _, v in pairs(chars) do
		if v:IsA'Model' and v ~= script.Parent then
			if v:FindFirstChild("HumanoidRootPart") then
			local charRoot = v:FindFirstChild("HumanoidRootPart")
			if (charRoot.Position - part).magnitude < SearchDistance then
				torso = charRoot
				Ragdoll.Parent = torso.Parent
				Ragdoll.Disabled = false
			elseif not v:FindFirstChild("HumanoidRootPart") then		
			if v:FindFirstChild("Torso") then
			local charRoot = v:FindFirstChild("Torso")
			if (charRoot.Position - part).magnitude < SearchDistance then
			torso = charRoot
			Ragdoll.Parent = torso.Parent
			Ragdoll.Disabled = false	
						end
					end		
				end	
		    end
		end
	end
	return torso
end

for _, zambieparts in pairs(zombie:GetChildren()) do
	if zambieparts:IsA'Part' and zambieparts.Parent:FindFirstChildOfClass("Humanoid") then
		zambieparts.Touched:connect(function(p)
			if not p.Parent:FindFirstChildOfClass("Humanoid") then
			elseif p.Parent:FindFirstChildOfClass("Humanoid").Health == 0 then
			elseif p.Parent.Name ~= zombie.Name and p.Parent:FindFirstChildOfClass("Humanoid").Health > 0  then -- damage
			local enemy = p.Parent
			local enemyhuman = getHumanoid(enemy)
			enemyhuman:TakeDamage(ZombieDamage)	
			print("ded")		
			hroot.Death:Play()			
			wait(6)	
			hroot.Death:Stop()			
			end
		end)
	end
end
