Why is my voxel traversal raytracing algorithm not accurate?

I’m porting over this voxel traversal algorithm to my roblox game. However im running into an issue.

Here is the initialization phase of the algorithm:

function WorldController:Raycast(Origin : Vector3, Direction : Vector3)	
	local MaxDistance = Direction.Magnitude
	Direction = Direction.Unit
	local Step = Direction:Sign()
	local RayPosition = Vector3.new(math.round(Origin.X), math.round(Origin.Y), math.round(Origin.Z))
	local RayScale = Vector3.new(math.abs(1/Direction.X), math.abs(1/Direction.Y), math.abs(1/Direction.Z))
	local RayLength1D = (RayPosition-Origin):Abs()*RayScale -- im fairly sure this line is the cause of my troubles

The RayLength1D is the same as tMax, RayScale is tDelta. I just used more clear names.

I’m fairly sure the initial calculation of RayLength1D is the issue, as when i grid align the Origin, it seems to work without flaw. (I can’t do that in my actual use case) The initialization of RayLength1D is needed due to the rounded RayPosition.

(The transparent blocks are the voxels traversed, and the purple line is where the actual ray should go, the blue is the starting voxel.)

Any help would be appreciated!