Pathfinding WayPoints having wrong Y Value

Hello, I’m currently using pathfinding to figure out a path. My problem is that for some reason the targetposition’s Y Value defaults to 0, even though I for a fact know its not (Printing out the Y Value which returns not a 0).

My Code:

local function Pathfinding(TEST_DESTINATION, character)


	local path = PathfindingService:CreatePath({
		AgentRadius = 2,
		AgentHeight = 10,
		AgentCanJump = false,
	})

	local waypoints
	local nextWaypointIndex = 0
	local reachedConnection
	local blockedConnection
	local function followPath(destination)

		local c = false
		local success, errorMessage = pcall(function()
			path:ComputeAsync(character.Position, destination)
		end)

		if success and path.Status == Enum.PathStatus.Success then
			-- Get the path waypoints
			waypoints = path:GetWaypoints()
			for i,v in pairs(waypoints) do
				local cc = Instance.new('Part')
				cc.Anchored = true
				cc.Size = Vector3.new(1,1,1)
				cc.Position = v.Position
				cc.Parent = workspace
				cc.CanCollide = false
			end
			
			blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
				-- Check if the obstacle is further down the path
				if blockedWaypointIndex >= nextWaypointIndex then
					-- Stop detecting path blockage until path is re-computed
					blockedConnection:Disconnect()
					-- Call function to re-compute new path

					followPath(destination)
					c = true


				end
			end)
			
			while nextWaypointIndex < #waypoints do

			-- Detect if path becomes blocked
				
				if c then
					break
				end
			
				
				nextWaypointIndex = nextWaypointIndex + 1
				character.Position = waypoints[nextWaypointIndex].Position
				
				
				wait(4)
				
			end
			
			


	
			--humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
		else
			warn("Path not computed!", errorMessage)
		end
	end
	
	followPath(TEST_DESTINATION)

end
local function MoveEvent(Plr, Destination, Object1, Object)
	
	local NewDestination = Vector3.new(Destination.X, Object1.Y, Destination.Z)
	Pathfinding(NewDestination, Object)
end

The MoveEvent is a remoteevent that’s connected whenever the Player presses. The object is the object that is going the pathfinding is originating from.

Any help is welcome!

Edit (Video of whats happening):

Edit 2:
Even manually setting the destination in the Path:ComputeAsync() with a Y position of 5 produces the same result. The waypoints Y Position is 0

What prints when you put

local function MoveEvent(Plr, Destination, Object1, Object)
	print(Object1)

In the code?

It prints out the Vector3 position of the part that is going to be moved using pathfinding. Its Y position is 5.

Ok, try changing it to

local NewDestination = Vector3.new(Destination.X, Object1.Y, Destination.Z)
print(NewDestination)

What does it print?

It prints the mouse click position, with the Y position at 5

Then in what part of the script does it say it’s 0?

After I compute the path, and use the path:GetWaypoints() then each waypoint has a Y position of 0. If you look at the video I added to the topic post, you’ll see what it does instudio.

Try putting a slope. I can’t tell what’s wrong, the waypoint’s position is at it’s center, so half of it will be in the ground, and the Y-level of the ground just so happens to be 0 in this case.

local success, errorMessage = pcall(function()
	path:ComputeAsync(character.Position, destination)
end)

The destination Y position prints out 5 after computing. The character.Position.Y also prints out 5 (The cyan part)

Even manually setting the destination using a vector3 with a non-zero Y Value produces this same result.

Even if the waypoint’s Y position is zero, it doesn’t seem to affect anything in the video. The waypoints are correctly generating, and waypoints aren’t supposed to float.

So waypoints are always supposed to generate on the ground? I overlooked that. Thanks for the help!