Button Hover Effect

So I am trying to have each button’s background become visible and change the text color while the mouse is hovering over it and then after the mouse leaves the button it will go back to how it was.

Code:
– Begin Variables

local EnterFacilityButton = script.Parent.MainFrame.EnterFacilityButton

local SelectTeamButton = script.Parent.MainFrame.SelectTeamButton

local ViewStoreButton = script.Parent.MainFrame.ViewStoreButton

local CreditsButton = script.Parent.MainFrame.CreditsButton

– End Variables

– Begin Functions

function Hovering(HoverButton)

HoverButton.BackgroundTransparency = 0

HoverButton.TexctColor3 = Color3.new(255, 255, 255)

end

function EndHovering(HoverButton)

HoverButton.BackgroundTransparency = 1

HoverButton.TexctColor3 = Color3.new(170, 170, 170)

end

– End Functions

– Begin Button Hover Check

if EnterFacilityButton.MouseEnter then

Hovering(EnterFacilityButton)

elseif EnterFacilityButton.MouseLeave then

EndHovering(EnterFacilityButton)

end

if SelectTeamButton.MouseEnter then

Hovering(SelectTeamButton)

elseif EnterFacilityButton.MouseLeave then

EndHovering(SelectTeamButton)

end

if ViewStoreButton.MouseEnter then

Hovering(ViewStoreButton)

elseif EnterFacilityButton.MouseLeave then

EndHovering(ViewStoreButton)

end

if CreditsButton.MouseEnter then

Hovering(CreditsButton)

elseif EnterFacilityButton.MouseLeave then

EndHovering(CreditsButton)

end

– End Button Hover Check

A screenshot of the setup:
Help1

(Sorry I forgot how to put Lua in the post)

You typed Texct, change it to Text

1 Like
-- Begin Variables

local EnterFacilityButton = script.Parent.MainFrame.EnterFacilityButton
local SelectTeamButton = script.Parent.MainFrame.SelectTeamButton
local ViewStoreButton = script.Parent.MainFrame.ViewStoreButton
local CreditsButton = script.Parent.MainFrame.CreditsButton

-- End Variables

-- Begin Functions

function Hovering(HoverButton)
     HoverButton.BackgroundTransparency = 0
     HoverButton.TexctColor3 = Color3.new(255, 255, 255)
end

function EndHovering(HoverButton)
     HoverButton.BackgroundTransparency = 1
     HoverButton.TexctColor3 = Color3.new(170, 170, 170)
end

-- End Functions

-- Begin Button Hover Check

if EnterFacilityButton.MouseEnter then
     Hovering(EnterFacilityButton)
elseif EnterFacilityButton.MouseLeave then
     EndHovering(EnterFacilityButton)
end

if SelectTeamButton.MouseEnter then
     Hovering(SelectTeamButton)
elseif EnterFacilityButton.MouseLeave then
     EndHovering(SelectTeamButton)
end

if ViewStoreButton.MouseEnter then
     Hovering(ViewStoreButton)
elseif EnterFacilityButton.MouseLeave then
     EndHovering(ViewStoreButton)
end

if CreditsButton.MouseEnter then
      Hovering(CreditsButton)
elseif EnterFacilityButton.MouseLeave then
      EndHovering(CreditsButton)
end

-- End Button Hover Check

What do you put before the code to do that?

Select the code and press Ctrl+Alt+C

Also thanks lol I can’t spell and for some reason that wasn’t giving me an error. I tried reading over everything but must have passed over it. ty

Oh wait now there is another issue… The backgrounds for the buttons are set to 1 so they are invisible, and when you press play they all just become visible even though I’m not hovering over even one of them.

1 Like

You should use:

GuiObject.MouseEnter:Connect(function()

end)

and not

if GuiObject.MouseEnter then

end

Such if statement does not exist.

Edit: I would also suggest looping through all buttons in a for loop and connecting a .MouseEnter event rather than writing one separately for each button.

1 Like