Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i make my TextButton’s properties change whenever a player’s mouse is hovering over it?

local mainGui = game.StarterGui.MainGui
local shopButton = mainGui.ShopButton
local shopHoverC = 10,20,10
local shopHoverS = 15,5,10,0

function shopButtonHovering()
   shopButton.Size = Udim2.new(shopHoverS)
   shopButton.BackgroundColor3 = Color3.new(shopHoverC)
end

I want it that when a player’s mouse hovers on shopButton it will run the function. Is there some event that makes it work? Also should it be in a LocalScript? Thanks!

2 answers

✓ Accepted answer

You can simply use the MouseEnter function

local mainGui = game.StarterGui.MainGui
local shopButton = mainGui.ShopButton
local shopHoverC = 10,20,10
local shopHoverS = 15,5,10,0

function shopButtonHovering()
   shopButton.Size = Udim2.new(shopHoverS)
   shopButton.BackgroundColor3 = Color3.new(shopHoverC)
end

shopButton.MouseEnter:Connect(shopButtonHovering)

3 comments

0

I didn't saw someone already answered it XD

0

cant you use local functions instead of global?

0

thanks for the help! Also using global functions still works :V

There is an event called "MouseEnter" in TextButton

script.Parent.MouseEnter:Connect(function() script.Parent.TextColor3 = Color3.fromRGB(255, 255, 255) end)

script.Parent.MouseLeave:Connect(function() script.Parent.TextColor3 = Color3.fromRGB(0, 0, 0) end)

This discussion is preserved as it was. New answers, comments, and votes are closed.