local function B(B)local c=BrickColor.Random()for B,o in pairs(B)do local m=Instance.new("\080\097\114\116")m.BrickColor=c m.Anchored=true m.CanCollide=false m.Size=Vector3.new(1,1,1)m.Position=o.Position m.Parent=workspace local g=game:GetService("\068\101\098\114\105\115")g:AddItem(m,6)end end local function c(B)local c=getPath(B)if c.Status==Enum.PathStatus.Success then for B,c in pairs(c:GetWaypoints())do local o=findTarget()if o and o.Humanoid.Health>0 then attack(o)break else humanoid:MoveTo(c.Position)humanoid.MoveToFinished:Wait()end end else humanoid:MoveTo(B.Position-TeddyAI.HumanoidRootPart.CFrame.LookVector*10)end end function patrol()local B=TeddyAI.Parent.TeddyWaypoints:GetChildren()local o=math.random(1,#B)c(B[o])end while true do patrol()end
--end

local function displayPath(waypoints)
	local color = BrickColor.Random()
	for index, waypoint in pairs(waypoints) do
		local part = Instance.new("Part")
		part.BrickColor = color
		part.Anchored = true
		part.CanCollide = false
		part.Size = Vector3.new(1, 1, 1)
		part.Position = waypoint.Position
		part.Parent = workspace
		local Debris = game:GetService("Debris")
		Debris:AddItem(part, 6)
	end
end

local function walkTo(destination)
	local path = getPath(destination)

	if path.Status == Enum.PathStatus.Success then
		for index, waypoint in pairs(path:GetWaypoints()) do
			local target = findTarget()
			if target and target.Humanoid.Health > 0 then
				attack(target)
				break
			else
				humanoid:MoveTo(waypoint.Position)
				humanoid.MoveToFinished:Wait()
			end
		end
	else
		humanoid:MoveTo(destination.Position - (TeddyAI.HumanoidRootPart.CFrame.LookVector * 10))
	end
end

function patrol()
	local waypoints = TeddyAI.Parent.TeddyWaypoints:GetChildren()
	local randomNum = math.random(1, #waypoints)
	walkTo(waypoints[randomNum])
end

while true do
	patrol()
end
