How would I go about making a gui appear on the players mouse when hovering over a gui

Im trying to make a system that runs a little bit like this:

Basically, when you right click, a gui will appear right next to the mouse. I tried setting the UI position to the mouse position and offessetting it by its size but it just won’t work due to ui.position only changing its position relative to its parent element.

I figured to only way to achieve this was to use absolute position but you cannot edit absolute position :confused:

I hope this article will help you, It provides a lot of useful information. I have tried this before and it works super well!!

Article: Displaying information on TextLabel following Mouse

check if the the frame size + mouse position is over the size of the screen

Explorer:
Screenshot 2023-01-20 111200

Local script:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local Mouse = Players.LocalPlayer:GetMouse()
local Frame = script.Parent:WaitForChild("Frame", math.huge)

UserInputService.InputBegan:Connect(function(Input, GameProcessed)
	if GameProcessed then
		return
	end

	if Input.UserInputType == Enum.UserInputType.MouseButton2 then -- you can do it for mobile too
		local ViewportSize = script.Parent.AbsoluteSize
		local FrameSize = Frame.AbsoluteSize

		local AnchorPoint = Vector2.new(0, 0)

		if FrameSize.Y + Mouse.Y > ViewportSize.Y then
			AnchorPoint += Vector2.new(0, 1)
		end

		if FrameSize.X + Mouse.X > ViewportSize.X then
			AnchorPoint += Vector2.new(1, 0)
		end

		Frame.AnchorPoint = AnchorPoint
		Frame.Position = UDim2.fromOffset(Mouse.X, Mouse.Y)
	end
end)

what does this do exactly? i dont get what its meant to do

sets the frame position to the mouse position then doing the calculations to look like the one in the image and so it wont go out of the screen