How do I Fix This Bug?

The Problem?

I want a tooltip to disappear when the mouse is not on a Gui Button.

:beetle: The Bug:

ezgif.com-gif-maker

*As you can see the Tooltip is appearing after my mouse left. Apparently, the Script is saying that if the Mouse is/was on the GUI Button show the Tooltip.

My Code:

--Variables
local Search_Bar_Background = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Search Bar Background"]
local Search_Bar = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Search Bar"]
local Search_Icon = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Search Icon"]
local Settings_Button = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Settings Button"]

--Search Bar Focused & Lost Focus Tweens
local TweenService = game:GetService("TweenService")

--Focused Tween Logic

--Search Bar Background Color Tween
local SBB_TweenColor = Color3.fromRGB(223, 223, 223)
local SBB_TweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local SBB_Tween = TweenService:Create(Search_Bar_Background, SBB_TweenInfo, {BackgroundColor3=SBB_TweenColor})

--Lost Focus Tween Logic

--Search Bar Background Color Tween
local SBB_TweenColor = Color3.fromRGB(232, 232, 232)
local SBB_TweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local SBB_Tween2 = TweenService:Create(Search_Bar_Background, SBB_TweenInfo, {BackgroundColor3=SBB_TweenColor})

--When Search Bar Focused Do
Search_Bar.Focused:Connect(function()
	SBB_Tween:Play()
	Search_Icon.ImageColor3 = Color3.fromRGB(184, 184, 184)
	Settings_Button.ImageColor3 = Color3.fromRGB(184, 184, 184)
	Search_Bar.PlaceholderColor3 = Color3.fromRGB(184, 184, 184)
end)

--When Search Bar Lost Focus Do
Search_Bar.FocusLost:Connect(function()
	SBB_Tween2:Play()
	Search_Icon.ImageColor3 = Color3.fromRGB(199, 199, 199)
	Settings_Button.ImageColor3 = Color3.fromRGB(199, 199, 199)
	Search_Bar.PlaceholderColor3 = Color3.fromRGB(199, 199, 199)
end)


--Settings Button Click Tween & Logic

--Variables
local Settings_Button_Click = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Settings Button Click"]
local Settings_Button_ToolTip = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Settings Button"]["Settings Button ToolTip"]

--Settings Button Tween Logic

--Settings Button Hover Tween
local SBC_TweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local SBC_Tween = TweenService:Create(Settings_Button_Click, SBC_TweenInfo, {Transparency = 0.5})

--Settings Button Leave Tween
local SBC_TweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local SBC_Tween2 = TweenService:Create(Settings_Button_Click, SBC_TweenInfo, {Transparency = 1})

--Settings Button ToolTip Tween Enter
local ST_TweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local ST_Tween = TweenService:Create(Settings_Button_ToolTip, ST_TweenInfo, {BackgroundTransparency = 0.4})

--Settings Button ToolTip Tween Leave
local ST_TweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local ST_Tween2 = TweenService:Create(Settings_Button_ToolTip, ST_TweenInfo, {BackgroundTransparency = 1})

--If Mouse Enter Settings Button Do
Settings_Button.MouseEnter:Connect(function()
	Settings_Button_Click.Visible = true
	SBC_Tween:Play()
	wait(1.5)
	Settings_Button_ToolTip.Visible = true
	ST_Tween:Play()
end)

--If Mouse Leave Settings Button Do
Settings_Button.MouseLeave:Connect(function()
	SBC_Tween2:Play()
	ST_Tween2:Play()
	wait(0.3)
	Settings_Button_ToolTip.Visible = false
	Settings_Button_Click.Visible = false
end)

I want the script to detect if the mouse is still on the GUI Button, then only show the Tooltip. How do I go about doing this?

looks like you enter then leave too fast, so your leave function finished after .3 but then your enter 1.5 wait finishes and it sets it back to visible

maybe something like this:

local Hovering = false
Settings_Button.MouseEnter:Connect(function()
	Hovering = true
	Settings_Button_Click.Visible = true
	SBC_Tween:Play()
	wait(1.5)
	if Hovering then
		Settings_Button_ToolTip.Visible = true
		ST_Tween:Play()
	end
end)

--If Mouse Leave Settings Button Do
Settings_Button.MouseLeave:Connect(function()
	Hovering = false
	SBC_Tween2:Play()
	ST_Tween2:Play()
	wait(0.3)
	if not Hovering then
		Settings_Button_ToolTip.Visible = false
		Settings_Button_Click.Visible = false
	end
end)

or

local Hovering = false
local ChangedTick = tick()
Settings_Button.MouseEnter:Connect(function()
	Hovering = true
	ChangedTick = tick()
end)

--If Mouse Leave Settings Button Do
Settings_Button.MouseLeave:Connect(function()
	Hovering = false
	ChangedTick = tick()
end)


while wait() do
	if Hovering then
		if tick() - ChangedTick > 1.5 then
			Settings_Button_ToolTip.Visible = true
			ST_Tween:Play()
		else
			Settings_Button_ToolTip.Visible = false
		end
	else
		Settings_Button_ToolTip.Visible = false
	end
end

The First Option worked for me! Thanks, @kylerzong! :grinning: