Bug that causes gui that follows mouse to disappear

Hello! I am coding a shop gui for an upcoming new game and am working on a gui that follows the mouse whenever it enters a button. It works perfectly, but I am having an issue where two functions override each other and the gui ends up not being visible whenever I move my mouse too fast. My video here will show what I mean.

Here is the code. Any ideas or help is greatly appreciated :smiley:

local Mouse = game.Players.LocalPlayer:GetMouse()
local MouseFrame = script.Parent.MouseFrame
local uis = game:GetService("UserInputService")

MouseFrame.Visible = false

Mouse.Move:Connect(function()
	MouseFrame.Position = UDim2.new(0, Mouse.X + 10, 0, Mouse.Y + 35)
end)

Style1.MouseEnter:Connect(function()
	MouseFrame.Visible = true
	MouseFrame.Product.Text = "Test Name!"
	MouseFrame.Desc.Text = "Testing..."
	MouseFrame.Robux.Text = "100 Robux"
end)

Style1.MouseLeave:Connect(function()  -- This is where the problem starts
	MouseFrame.Visible = false
end)

Style2.MouseEnter:Connect(function()
	MouseFrame.Visible = true
	MouseFrame.Product.Text = "Testing 2"
	MouseFrame.Desc.Text = "Test #2"
	MouseFrame.Robux.Text = "30 Robux"
end)

Style2.MouseLeave:Connect(function() 
	MouseFrame.Visible = false
end)

Is there any way this bug can be avoided?

2 Likes

So your problem is that the already visible frame is going visible then invisible. It should go from visible, to invisible, back to visible. Your MouseEnter functions should check if the MouseFrame is invisible. If it is invisible, then make it visible. If itā€™s visible, then wait until the MouseLeave function has fired then make it visible again. Just an idea, not sure if itā€™ll work.

2 Likes

You can try adding some sort of debounce between the functions with a very little wait.

2 Likes

Is there a function for that? If so, that could work. I donā€™t know any way to check when the function has fired.

1 Like

Could you give a small piece of code to elaborate what you mean? Adding wait(0.05) doesnā€™t really help.

1 Like

I canā€™t really because Iā€™m on phone, I mean if you had a variable that turns on when your mouse hovers over one of the guis, and while the variable is ā€œonā€ (equals true or whatever), it wonā€™t show you info to a different gui, and then when your mouse leaves the first gui the variable will turn off again (become false). This will stop the overlapping problem

2 Likes

You can wait for an event with :Wait(), however you have many different mouse leave events, so Iā€™m not exactly sure how that would work.
Youā€™d have a better chance with using a loop or something.

Style1.MouseEnter:Connect(function()
	if MouseFrame.Visible == true then
		repeat task.wait() until MouseFrame.Visible == false
	end
	MouseFrame.Visible = true
	MouseFrame.Product.Text = "Test Name!"
	MouseFrame.Desc.Text = "Testing..."
	MouseFrame.Robux.Text = "100 Robux"
end)

Using an if statement might make things even worse, but the MouseFrame should always be invisible if you are entering. If it is visible when entering, then you wait for whatever mouse leave function hasnā€™t fired yet.

3 Likes

Yup! It works! Thank you so much for your help. I greatly appreciate it <3

2 Likes
if MouseFrame.Visible then
	MouseFrame:GetPropertyChangedSignal("Visible"):Wait()
end

Instead of polling why not create an RBXScriptSignal object for the frameā€™s ā€œVisibleā€ property?

4 Likes