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

while true do
	patrol()
end
