Making a gui follow a part & clamp it to screen edges?

  1. What do you want to achieve?
    pretty much the same thing as the title, I want to track a part and make sure the gui is always at the closest edge to the object

  2. What is the issue?
    the gui moves to the middle of the screen when looking directly away, and I don’t know how to make it so that the label tries to move offscreen instead of whatever this is



  3. What solutions have you tried so far?
    tried clamping it and it sort of works but once i go into extreme angles when the object is off screen it stops working properly and fails to try to reach the object

heres my code:

local runService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local textLabel = game.Players.LocalPlayer.PlayerGui:WaitForChild("text").Frame.TextLabel
local part = workspace:WaitForChild("billboard")

runService:BindToRenderStep("FollowWorldPosition", Enum.RenderPriority.Last.Value, function(deltaTime)
	local screenPoint, isInBounds = camera:WorldToScreenPoint(part.Position)
	local screenWidth = camera.ViewportSize.X
	local screenHeight = camera.ViewportSize.Y

	
	if isInBounds then
		textLabel.Position = UDim2.new(0, screenPoint.X, 0, screenPoint.Y)
	else
	
		local clampedX = math.clamp(screenPoint.X, 0, screenWidth)
		local clampedY = math.clamp(screenPoint.Y, 0, screenHeight)


		textLabel.Position = UDim2.new(0, clampedX, 0, clampedY)
	end

end)