Random goofy attempted horror game

lol im just here for some random aaa stuf. im just gonna share whatever goes on with my messed up goofy game

In sentence. No images cuz its not my laptop :alien:

some simple AI killing script from GnomeCode but it seems not to be working and the monster is just circling around nothing

task.wait()

local PathfindingService = game:GetService('PathfindingService')
 
local ted = script.Parent
local humanoid = ted.Humanoid

ted.PrimaryPart:SetNetworkOwner(nil)

local function canSeeTarget(target)
	local origin = ted.HumanoidRootPart.Position
	local direction = (target.HumanoidRootPart.Position - ted.HumanoidRootPart.Position).unit*40
	local ray = Ray.new(origin, direction)

	local hit, pos = workspace:FindPartOnRay(ray, ted)


	if hit then
		if hit:IsDescendantOf(target) then
			return true
		end
	else
		return false
	end
end

local function findTarget()
	local players = game.Players:GetPlayers()
	local maxDistance = 40
	local nearestTarget

	for index, player in pairs(players) do
		if player.Character then
			local target = player.Character
			local distance = (ted.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

			if distance < maxDistance and canSeeTarget(target) then
				nearestTarget = target
				maxDistance = distance
			end
		end
	end

	return nearestTarget
end

local function getPath(destination)
	local pathParams = {
		['AgentHeight'] = 7.3,
		['AgentRadius'] = 2.8,
		['AgentCanJump'] = false
	}
	local path = PathfindingService:CreatePath(pathParams)
	
	path:ComputeAsync(ted.HumanoidRootPart.Position, destination.Position)

	return path
end

local function attack(target)
	local distance = (ted.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

	if distance > 9.4 then
		humanoid:MoveTo(target.HumanoidRootPart.Position)
	else
		target.Humanoid.Health = 0
	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 then
				print(target.Name)
				attack(target)
				break
			else
				humanoid:MoveTo(waypoint.Position)
				humanoid.MoveToFinished:Wait()
			end
		end
	else
		humanoid:MoveTo(destination.Position - (ted.HumanoidRootPart.CFrame.LookVector * 10))
	end
end

function patrol()
	local destinations = workspace.mazepaths:GetChildren()
	local randomNum = math.random(1, #destinations)
	walkTo(destinations[randomNum])
end

while wait(.5) do
	patrol()
end

ok i fixed it with the pathParams no biggie

I added a key in the maze so u can obviously escape oh wait- THERES A MONSTER TOO HAHA

I was asleep now im awake i finally finished the maze so i cant make the final vault