Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

BillboardGui Hovering (MouseLeave not working?)

Asked by 8 years ago

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)
0
What the heck is line 9 doing? User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Line 9 is going crazy!

The best way I could suggest fixing this would be to redo line 9.


How to call functions,

Here's an example of calling a function that will print Hello World!.

local function Print()
    print("Hello World!")
end

Print()-- function call

How to use events to call functions,

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)
The Above Will Print "Hello World!" When The Part Is Clicked

Your problem,

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 moved the function calls for slight efficiency

I hope that works.

Good Luck!

0
Thanks for your answer. This is good advice - I didn't set the functions and signals up in an ideal way. I think there is another problem here though, perhaps a bug that doesn't allow BillBoard guis to reliably use MouseLeave (see this forum post: http://forum.roblox.com/Forum/ShowPost.aspx?PostID=93718459 ) Akkurat 5 — 8y
Ad

Answer this question