Nil in PathfindingService

so, i was making a Baldi’s basics game and the problem started when i tried to make a pathfinding AI for baldi

everytime i try to execute the script, it returns nil. for some reason

i tried to search the internet for a solution. but some i couldn,t understand, and some it didn,t solved my problem

i don,t know if is the problem on the script or in the map itself

(Note: i tried to keep the npc far away from the map (with a baseplate), and he didn,t moved anyway)

local Position = 1
local Pathfinding
local Wp

function ChoosePosition()
	local Pos
	local Value = 100

	if Pathfinding then
		if (RootPart.Position - Pathfinding[Position]).Magnitude <= 4 then
			Position += 1
			Pos = Wp[tostring(Position)].Position
		end
	end

	if not Pathfinding or (Position >= #Pathfinding) then
		Pos = Vector3.new(math.random(-Value,Value),0,math.random(-Value,Value))
		Pathfinding = PathfindingSvc:CreatePath({	["AgentRadius"] = 1})
		Pathfinding:ComputeAsync(RootPart.Position, Pos)
		
		if Pathfinding then
			Wp = Pathfinding:GetWaypoints()
			Position = 1
			Pos = Wp[tostring(Position)].Position
		else
			wait()
			return ChoosePosition()
		end
	end

	return Pos
end

while task.wait(SlapPerSecond.Value) do
	if (RootPart.Position - GoalCFrame.Value.Position).Magnitude <= 4 then
		GoalCFrame.Value = CFrame.new(ChoosePosition())
		print(1)
	end

	SlapSound:Play()

	Humanoid:MoveTo(GoalCFrame.Value.Position)

	for i, Image in pairs(SpriteSequence) do
		CharacterImg.Image = Image
		wait(0.05)
	end

	Humanoid:MoveTo(RootPart.Position)
end