Roblox mouse position to frame position

I made a script that if I hover over button a frame is visible and if I dont hover its not visible which works but I wanted the position of the frame to be the position of the mouse, so I got the position of the mouse and changed the frame postiion tp the mouse position but it doesnt work, any help?

local Players = game:GetService("Players")

local Gui = script.Parent.Hard
local InfoGui = script.Parent.HardHover

local Entered = false

Gui.MouseEnter:Connect(function()
	Entered = true
	InfoGui.Visible = true
end)

Gui.MouseLeave:Connect(function()
	Entered = false
	InfoGui.Visible = false
end)

Reference

Can you send the part where you moved the frame to the mouse?

You can use UserInputService:GetMouseLocation() to return offset values you can then use to change the position.

1 Like
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

print(Mouse.X, Mouse.Y)

Is this what you mean?

local Players = game:GetService("Players")

local mouse = Players.LocalPlayer:GetMouse()

local Gui = script.Parent.Hard
local InfoGui = script.Parent.HardHover
local frame : Frame = InfoGui.Frame --im not sure where your frame is located. replace "InfoGui.Frame" with your frame

local Entered = false

local normalpos = frame.Position

Gui.MouseEnter:Connect(function()
	Entered = true
	InfoGui.Visible = true
	frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
end)

Gui.MouseLeave:Connect(function()
	Entered = false
	InfoGui.Visible = false
	frame.Position = normalpos
end)

This script doesn nothing. I need the script to when I hover over a button the frame is next to them mouse, following it. Your script doesnt follow and only works once.

local mouse = game:GetService("Players").LocalPlayer:GetMouse()

mouse.Move:Connect(function()
    frame.Position = UDim2.fromOffset(mouse.X, mouse.Y) --will set to on the mouse, adjust as needed
end)

You can’t do MouseEnter or MouseLeave to a gui.

nvm my bad

hhhhhhhhhhhhhhhhhhhhhh

local Gui = script.Parent.Hard
local InfoGui = script.Parent.HardHover

local Entered = false

local function updateInfoGuiPosition(mousePosition)
	local offsetX = -10 
	local offsetY = -30  

	local mouseX = mousePosition.X
	local mouseY = mousePosition.Y

	InfoGui.Position = UDim2.new(-0.29, mouseX + offsetX, -1.65, mouseY + offsetY)
end

Gui.MouseEnter:Connect(function()
	Entered = true
	InfoGui.Visible = true

end)

Gui.MouseLeave:Connect(function()
	Entered = false
	InfoGui.Visible = false
end)

game:GetService("UserInputService").InputChanged:Connect(function(input)
	if Entered and input.UserInputType == Enum.UserInputType.MouseMovement then
		updateInfoGuiPosition(input.Position)
	end
end)

so have you figured it out or have you not?

Yes I have thank you for the help

I didn’t really help lol but np.

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