MouseEnter and MouseLeave don't work on SurfaceGui?

I put this script in a surfaceGui button.

script.Parent.MouseEnter:Connect(function()
	script.Parent.Parent.VentilationArrow.TextTransparency = 0
	script.Parent.Parent.VentilationArrow.UIStroke.Transparency = 0
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent.Parent.VentilationArrow.TextTransparency = 1
	script.Parent.Parent.VentilationArrow.UIStroke.Transparency = 1
end)

It just simply does nothing and it doesn’t print any errors.

1 Like

you can’t do mouse enter or leave on surface gui. Mouse Leave and Mouse Enter are not objects of .SurfaceGui. You can call the .mouse events on one of the children that do have the event

local GUi = script.Parent
local Object = GUi.Frame --- change this to your ui child thats inside the Surface gui
Object.MouseEnter:Connect(function()
--stuff
end)
Object.MouseLeave:Connect(function()
-- stuff
end)

I know i literally put in the first line of the post that I put the script in a button.

oh my bad I thought you were putting it on the surface gui

1 Like

It needs to be a local script. But local scripts don’t run in Workspace (with the exception of being in a character). There are really 2 ways to solve this. Put the local script somewhere it does run like in starter gui or put the surface gui in starter guis and set it’s adorned to the part it should be on. This tutorial can help In-Experience UI Containers | Roblox Creator Documentation

Yeah I did that and it still doesn’t work

If you put a print at the top does it print it?

yes

print("e")

It prints

I put prints inside of the MouseEnter and MouseLeave functions and it doesn’t print

Well at this point you’ve done everything I can think of without having access to studio myself to test. The last thing I can think to do is check that your script works in a screen gui which would rule out most script issues. But if the screen gui does work but surface doesn’t then I’m out of ideas.

Yeah I copied it into a screen gui and the script worked with the screen gui, but I need it to be a surface gui

Update: I made the background transparency 0 and selected “AutoButtonColor” and when I hover over it the background doesn’t turn darker as expected. For some reason the button just isn’t working at all I think.

Another update: I got the button working by moving it VERY close to the player’s face, and I have no idea why because there was never a single invisible part blocking the way of it, so I don’t know why moving it super close to the player’s face makes it responsive, but I need to figure out how to get it working from a distance.

Okay I figured it out. For some reason I couldn’t click the button because of an invisible part that was behind the players head. (Seriously it was barely touching the head) So I’m trying to figure out how to fix it.

It seems to fix it if you set the surfacegui’s alwaysontop property to true.

Sorry I’m extremely late to this lol I just had this problem and it seems that fixed it.