Hover not working correctly

Hello, developers! I’m making buttons to access shops, skip stage, ect. and I have it so when you hover over a button it shows text of what the button is, but there’s a problem! When I hover over them they work fine but sometimes the text stays visible when I’m not hovering over the button. It seems to happen more when I move my cursor down across the buttons. Here is a video I took of it:

And here is my code for each hover text:

script.Parent.Parent.Button.MouseEnter:Connect(function()

script.Parent.Visible = true

end)

script.Parent.Parent.Button.MouseLeave:Connect(function()

script.Parent.Visible = false

end)

(Local script)
Thanks for the help!

You may want to add a bool value to make sure that It’s allowed to happen

local canShow = false

script.Parent.Parent.Button.MouseEnter:Connect(function()
    if canShow ~= true then
        canShow = true
        script.Parent.Visible = true
    end
end)

script.Parent.Parent.Button.MouseLeave:Connect(function()
    if canShow ~= false then
        canShow = false
       script.Parent.Visible = false
    end
end)

No, it didn’t work. But thanks for trying! :slight_smile:

Does it have the same mistake as last time?

Also, how come you have to mouses?

Yes, it’s all the same. I’m going to try making 1 script for all.

It’s because of my recorder, it does that sometimes. Not sure why.

Ok, try this:

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

script.Parent.Parent.Button.MouseEnter:Connect(function()
    if mouse.Target:IsA("ImageButton") then
        script.Parent.Visible = true
    end
end)

script.Parent.Parent.Button.MouseLeave:Connect(function()
    if mouse.Target:IsA("ImageButton") then
        script.Parent.Visible = false
    end
end)

I’m really sorry if it doesn’t work

Sometimes MouseEnter and MouseLeave not working, InputChanged is more trustworthy

script.Parent.Parent.Button.InputChanged:Connect(function(Input: InputObject)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		script.Parent.Visible = true
		Input.Changed:Connect(function()
			if Input.UserInputState == Enum.UserInputState.End then
				script.Parent.Visible = false
			end
		end)
	end
end)

when the movement leaves the button, Input.Changed will detect it and hide the UI.

Hi thanks for your response! When I hover over it, the text becomes visible. However, when I move my mouse somewhere else it stays visible.

It doesn’t work, but thanks for trying!

Changed a couple things around and it works!
Here’s the script!

script.Parent.Parent.Button.InputChanged:Connect(function(Input: InputObject)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		script.Parent.Visible = true
		Input.Changed:Connect(function()
			if Input.UserInputState == Enum.UserInputState.Change then
				script.Parent.Visible = false
			end
		end)
	end
end)