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:
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)
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)
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.
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)