Hello!
I’m trying to play a SFX every time a player hovers over a TextButton or an ImageButton.
I know a method with .MouseEnter
, but it detects if the mouse is on a specific Text- or ImageButton.
Is there a way to make the script check if the player is hovering over ANY Text- or ImageButton?
Instead of making a localscript inside button, make a localscript inside gui, and then use .MouseEnter for every descendant that is TextButton or ImageButton
Local script
local gui = script.Parent
for _, child in pairs(gui:GetDescendants()) do
if child:IsA("TextButton") or child:IsA("ImageButton") then
child.MouseEnter:Connect(function()
print("entered") --your code here
end)
end
end
This is how it looks for me in explorer, but thanks to :GetDescendants(), it should also work with buttons nested inside new frames etc.
Hi, try this
local hovering = false
Youruttin.MouseEnter:Connect(function()
hovering= true
else
hovering= false
end)
if hovering == true then
-- it's hovering
end
I’m on Mobile right now so I couldn’t do the formatting.
I completely forgot about this, thank you very much.
but you cant format on pc unless you copy a tab character
Anyways I think you forgot something.