Help with GUI following mouse

I want to make the informationframe follow the mouse whenever the mouse hovers on the template but whenever I hover over the template, the informationframe shows up for like 2 frames and then stops following the mouse, what did I do wrong? I tried changing the UDim2 in the script from offset to scale and that didn’t help

Video

local location = game:GetService('UserInputService'):GetMouseLocation()
	
	template.MouseEnter:Connect(function(x,y)
		informationframe.Visible = true
		rs.Heartbeat:Connect(function()
			informationframe.Position = UDim2.new(0,location.X,0,location.Y)
		end)
	end)
	
	template.MouseLeave:Connect(function()
		informationframe.Visible = false
	end)

Its because you only got the mouse position once. Therefore it only runs 2 frames because that’s how long the frame overlaps the position of the mouse. Do this instead

local uis = game:GetService('UserInputService')
template.MouseEnter:Connect(function()
   isintemplate = true
end)
template.MouseLeave:Connect(function()
   isintemplate = false
end)
rs.Heartbeat:Connect(function()
  if not isintemplate then return end
  local location = uis:GetMouseLocation()
  informationframe.Position = UDim2.new(0,location.X,0,location.Y)
end)

This helped but now it appears in the right position for a few frames again and then goes back down to the right. It does follow the mouse though which is good

Could you like show me a vid of your issue, I cant tell which one you’re trying to move and how its buggy

Sorry the last link was the wrong video this is the right one: Watch video | Streamable

Instead of UIS I would recommend using AbsolutePosition.

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

local function uLocation()
	local locationX = mouse.X - template.AbsolutePosition.X
	local locationY = mouse.Y - template.AbsolutePosition.Y
	informationframe.Position = UDim2.new(0,locationX,0,locationY)
end

template.MouseEnter:Connect(function()
	informationframe.Visible = true
	mouse.Move:Connect(uLocation)
end)

template.MouseLeave:Connect(function()
	informationframe.Visible = false
end)

made it so it would automatically work when you paste it in (hopefully)

2 Likes

Thank you! Can you explain what you did because I never really understood how to use AbsolutePosition and I want to learn

1 Like

AbsolutePosition identifies every UI to start from 0,0 from the top left of your screen giving the right position but :GetMouseLocation() for whatever reason when trying to do something with UI it starts the 0,0 on the top left of the UI so if you had a text button in the middle of the screen and top left of the frame somewhere around there then when hovering over that text button it would actually be in the middle of the 0,0 starting from the top left of the frame so it would be somewhere in the bottom right, and that is how I understand :GetMouseLocation() and AbsolutePosition.

1 Like

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