Hover Over Gui offset getting larger

So I have a script, that opens a gui upon hovering on a frame. The problem is, when there are multiple frames, for some reason the offsets get larger and larger. This is what I mean. They are all separate frames, parented under their respective frames.

It most probably has something to do with the positioning formula. If you will share that portion of the code, I (or someone else) might be able to help.

whoops, forgot to include that but here,

local hovering = false
local hoverSoundPlayed = false

script.Parent.MouseEnter:Connect(function()
	hovering = true
end)
script.Parent.MouseLeave:Connect(function()
	hovering = false
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if hovering then
		if not hoverSoundPlayed then
			hoverSoundPlayed = true
			script.Parent.Parent.Parent.Parent.Parent.Parent["ui hover"]:Play()
		end
		local mousePos = game:GetService("UserInputService"):GetMouseLocation()

		script.Parent.InfoFrame.Position = UDim2.new(0, (mousePos.X - 280), 0, (mousePos.Y))
		script.Parent.InfoFrame.Visible = true
		wait(0.1)
	else
		hoverSoundPlayed = false
		script.Parent.InfoFrame.Visible = false
		wait(0.1)
	end
end)

It appears that each of the frames has a script like this, and in that case, you’re positioning the InfoFrame relative to them, regardless of using Offset instead of Scale, Offset is still relative to the Parent, it’s not the same as AbsolutePosition - though it can be if the Parent’s AbsolutePosition is (0, 0).

The quickest fix would be to add Script.Parent.AbsolutePosition into the equation, but you should reconsider using a separate script for each of the frames, and also using RenderStepped.

You only need one InfoFrame, and you can change its contents based on which frame is being hovered (and also show/hide it based on if a frame is being hovered).

You can use the Frame.InputChanged event to keep track of pointer movement over them, that way you can avoid RenderStepped (even MouseEnter/MouseLeave if you want).

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