How would I make this Ai script wander around instead of following the player automatically

So I found this Ai script somewhere on the interwebz and I would like it to wander around until it finds a player then the Ai follows them until they lose them. But I have no Idea on how to do this so could anyone help?

local Pathfinder = require(game.ReplicatedStorage.Modules:WaitForChild("Pathfind"))

local Torso = script.Parent:WaitForChild("HumanoidRootPart")
local Humanoid = script.Parent:WaitForChild("Humanoid")

function Follow_Path(Goal)
	if not Goal then return end

	local Path = Pathfinder(Torso.Position, Goal)

	for _,Node in ipairs(Path)do
		repeat wait()
			Humanoid:MoveTo(Node)
			until (Node - Torso.Position).Magnitude <= 4
	end
end


function GetClosestPlayer(To)
	local Distance = 25
	local Output = nil
	for _,Player in ipairs(game.Players:GetPlayers())do
		local Diff = Player:DistanceFromCharacter(To)
		if Diff < Distance and Player.Character then
			Distance = Diff
			Output = Player.Character
		end
	end
	return Output
end

while wait() do
	local Player = GetClosestPlayer(Torso.Position)
	if Player and Player:FindFirstChild("Torso") then
		Follow_Path(Player.Torso.Position)
	end
end
1 Like

Use the Follow_Path function defined in your script and then just make a random position to put in that function