I have MouseEnter and MouseLeave signals set up for a TextButton inside a BillboardGui. The BillboardGui is located in the PlayerGui and the following code runs inside the BillboardGui in a LocalScript.
For whatever reason, MouseLeave won't fire. The button appears hovered even when the mouse leaves the button. The button is only reset when clicked on (and MouseEnter fires again). Any idea of what the problem could be, or any potential workarounds? Thanks!
function MouseEnter(button) doSomething() button.MouseLeave:connect(function() doSomething() end) end button.MouseEnter :connect(function() MouseEnter(button) end)
The best way I could suggest fixing this would be to redo line 9.
Here's an example of calling a function that will print
Hello World!
.
local function Print() print("Hello World!") end Print()-- function call
Here's an example of an event that will connect to a function that prints Hello World, like before, but it's now connected to an event.
local ClickDetect = script.Parent:WaitForChild("ClickDetector") local function print() print("Hello World!") end ClickDetect.MouseClick:connect(print)
Your problem is that you're using function calls wrong. You also seem to think that the MouseEnter gives that button. This is false. Define your button before hand for less errors. Here's what your script should look like,
local button = script.Parent--Define your button function MouseEnter(mouse) button.MouseLeave:connect(function() doSomething() end) doSomething()--I moved this end button.MouseEnter:connect(MouseEnter)
Or, optionally,
local button = script.Parent--Define your button button.MouseEnter :connect(function(mouse) button.MouseLeave:connect(function() doSomething() end) doSomething()-- I moved this end
I hope that works.
Good Luck!