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

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

  1. What do you want to achieve? I want too make a gui that will pop up on the mouse when a player hovers there mouse over a button

  2. What is the issue? I don’t know where to start

  3. What solutions have you tried so far? I tried finding stuff on the developer hub

So I have a inventory system and I needed a way too show stats of items so I thought that making a gui appear on the players mouse when hovered over would be a good idea but I don’t know where to start on something like this.

Any help would be appreciated.

Check out userinputservice’s GetMouseLocation function
https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetMouseLocation

It’s code sample seems similar to what your trying to achieve. Being that you want to move a gui to the mouse position

What would you do is

When player hover mouse on GUIs, you would use RenderStepped so any gui (that you want to put) will update and be on the mouse. (make the gui visible true)

And then inside the RenderStepped event, update the X and Y position of the gui by using player:GetMouse X and Y.

Here is an simple example (frame is the item in the inventory and statsFrame is the frame that shows that stats of the items):

local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

frame.MouseEnter:Connect(function()
	statsFrame.Visible = true
end)

frame.MouseLeave:Connect(function()
	statsFrame.Visible = false
end)

local function renderStepped()
	if statsFrame.Visible then
		local mouseLoc = UIS:GetMouseLocation()
		local mousePos = UDim2.fromOffset(mouseLoc.X,mouseLoc.Y)
		statsFrame.Position = mousePos
	end
end
	
RS.RenderStepped:Connect(renderStepped)

also, make sure you have ignoreguiinset on so the mouse location is accurate

sorry everyone for not responding i found the solution already but thank you for your responses anyway

1 Like

Do you know what the solution was? I’ve been searching for an hour now trying to find a solution.