Frame's position relative to Mouse's position

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make the frame’s position relative to the mouse’s position.

  2. What is the issue? The frame is far from the mouse’s current position.

  3. What solutions have you tried so far? I have tried to use “.AbsolutePosition” instead.

local Players = game:GetService("Players")
local Localplayer = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Mouse = Localplayer:GetMouse()
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tools = ReplicatedStorage:WaitForChild("Tools"):GetChildren()
local HoverItemGUI = script:WaitForChild("HoverItem")
local ToolsName = {}

for i,v in pairs(Tools) do 
	table.insert(ToolsName, v.Name)
end

HoverItemGUI:Clone().Parent = Localplayer.PlayerGui
local NewHoverItemGUI = Localplayer.PlayerGui:WaitForChild("HoverItem")
local MainFrame = NewHoverItemGUI:WaitForChild("Main")

RunService.RenderStepped:Connect(function()
	local MousePos = UserInputService:GetMouseLocation()
	local Target = Mouse.Target
	if Target then
		local TargetParent = Target.Parent
		if ToolsName then
			if table.find(ToolsName, TargetParent.Name) then
				MainFrame.Visible = true
				MainFrame.Position = UDim2.fromOffset(MousePos.X, MousePos.Y)
			else 
				MainFrame.Visible = false
			end
		end
	end
end)

Here is what I mean:
image

Did you forget set the ScreenGui to ignore inset?
image

Also, the frame that the text is in could mess up the text position if it’s size or position is scaled.

True, it may be the frame. I will check.

Thank you very much. I only needed to center the frame and set the anchorpoint to 0.5, 0.5.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.