function getHumanoid(l)for l,s in pairs(l:GetChildren())do if s:IsA("\072\117\109\097\110\111\105\100")then return s end end end local l=script.Parent local s=getHumanoid(l)local L=l.HumanoidRootPart local Q=L.Velocity.magnitude local H=game:GetService("\080\097\116\104\102\105\110\100\105\110\103\083\101\114\118\105\099\101")function GetPlayerNames()local l=(game:GetService("\080\108\097\121\101\114\115")):GetChildren()local s=nil for l,L in pairs(l)do if L:IsA("\080\108\097\121\101\114")then s=tostring(L.Name)end end return s end spawn(function()while wait()do wait(0)end end)function GetPlayersBodyParts(l)local s=l if s then local l=s.Parent for l,s in pairs(l:GetChildren())do if s:IsA("\080\097\114\116")then return s.Name end end else return"\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"end end function GetTorso(l)local s=game.Workspace:GetChildren()local L=nil for s,Q in pairs(s)do if Q:IsA("\077\111\100\101\108")and(Q~=script.Parent and Q.Name==GetPlayerNames())then local s=Q:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if(s.Position-l).magnitude<SearchDistance then L=s end end end return L end for s,L in pairs(l:GetChildren())do if L:IsA("\080\097\114\116")then L.Touched:connect(function(s)if s.Parent.Name==GetPlayerNames()and s.Parent.Name~=l.Name then local l=s.Parent local L=getHumanoid(l)L:TakeDamage(aiDamage)end end)end end



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


local ai = script.Parent
local human = getHumanoid(ai)
local hroot = ai.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
		wait(0)
	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 and v.Name == GetPlayerNames() then
			local charRoot = v:FindFirstChild'HumanoidRootPart'
			if (charRoot.Position - part).magnitude < SearchDistance then
				torso = charRoot
			end
		end
	end
	return torso
end

for _, zambieparts in pairs(ai:GetChildren()) do
	if zambieparts:IsA'Part' then
		zambieparts.Touched:connect(function(p)
			if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= ai.Name then -- damage
				local enemy = p.Parent
				local enemyhuman = getHumanoid(enemy)
				enemyhuman:TakeDamage(aiDamage)
			end
		end)
	end
end
