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