Code randomlly stopped working in render step?

So this probably isn’t the best solution, but this is the code I’ve been using to detect when the player is at the edge of the screen

function WorldToScreen(Pos) --This function gets a World Position (Pos) and returns a Vector2 value of the screen coordinates
	local point = workspace.CurrentCamera.CoordinateFrame:pointToObjectSpace(Pos)
	local aspectRatio = Mouse.ViewSizeX / Mouse.ViewSizeY
	local hfactor = math.tan(math.rad(workspace.CurrentCamera.FieldOfView) / 2)
	local wfactor = aspectRatio*hfactor

	local x = (point.x/point.z) / -wfactor
	local y = (point.y/point.z) /  hfactor

	return Vector2.new(Mouse.ViewSizeX * (0.5 + 0.5 * x), Mouse.ViewSizeY * (0.5 + 0.5 * y))
end

RunService.RenderStepped:Connect(function()
	local Vec2 = WorldToScreen(HRP.Position)
	warn(Vec2)	
	if Vec2.X <= 229 or Vec2.X >= 1111 then
		if (UIS:IsKeyDown(Enum.KeyCode.D) and Character.CurrentFacingDirection == 1) or 
			UIS:IsKeyDown(Enum.KeyCode.A) and (Character.CurrentFacingDirection == -1) then
			Character:AdjustMovement("WalkSpeed",17)
		else
			Character:AdjustMovement("WalkSpeed",0)
		end
	else
		Character:AdjustMovement("WalkSpeed",17)
	end	
end)

However recently the code just stopped working the values returned from Vec2 don’t change however if I put the code inside of a while loop it works just fine, but the RenderStepped is already a loop so what’s causing this to happen the rest of the code in the RenderStepped (which I cut out from this) works just fine so no idea what’s going on here.

Might be worth adding a tick() or two to allow things to run smoothly (you may be attempting to perform too many operations in a single frame.