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