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

Avoiding failure to fire .MouseEnter?

Asked by
Ripull 45
10 years ago

When you have 2 Guis side by side, MouseEnter messes up in the fact that when your mouse goes from 1 Gui to another, MouseLeave is fired at the same time as MouseEnter or something.. You guys get it..

No gap between guis = messed up mouse enter functions, miss-firing functions etc. How can I avoid this? Spacing out the guis is all I know of, but that won't work in my current situation. I need the guis to stay together.

local player = game.Players.LocalPlayer

for _, v in pairs(script.Parent:GetChildren()) do
    if v:IsA("ImageButton") then




        v.MouseEnter:connect(function()

            for i,v in pairs(script.Parent:GetChildren()) do
                if v:IsA("ImageButton") then
                script.Parent[v.Name].BackgroundColor3 = Color3.new(0,0,0)
                end
                end

        if v.LightUp.Value == "T RA LA" then
        script.Parent.Torso.BackgroundColor3 = Color3.new(1,1,0)
                script.Parent.RightArm.BackgroundColor3 = Color3.new(1,1,0)
                        script.Parent.LeftArm.BackgroundColor3 = Color3.new(1,1,0)

        elseif v.LightUp.Value == "RL LL" then
        script.Parent.RightLeg.BackgroundColor3 = Color3.new(1,1,0)
                script.Parent.LeftLeg.BackgroundColor3 = Color3.new(1,1,0)

        elseif v.LightUp.Value == "H" then
        script.Parent.Head.BackgroundColor3 = Color3.new(1,1,0)


        end

        end)





        v.MouseLeave:connect(function()

            for i,v in pairs(script.Parent:GetChildren()) do
                if v:IsA("ImageButton") then
                script.Parent[v.Name].BackgroundColor3 = Color3.new(0,0,0)
            end
            end

        end)

    end
end
0
This is a common known problem. For now until it's fixed you might just want to make your own custom event using the mouse "Move" event. User#3 0 — 10y

1 answer

Log in to vote
0
Answered by
AxeOfMen 434 Moderation Voter
10 years ago

I have an Image label that acts as a hint when hovering the mouse over my interface buttons. When moving the mouse from one button to another, the hint would sometimes not show when it should. Here is how I addressed the problem:

local next = next --redefine global "next" for efficiency
local hoverBtns = {}

local mouseIn = function(button, hintText, pos)
    hint.TextLabel.Text = hintText
    hint.Position = pos
    hoverBtns[button] = true
    hint.Visible = true
end

local mouseOut = function(button)
    hoverBtns[button] = nil
    --check for table emptiness
    if next(hoverBtns) == nil then
        hint.Visible = false
    end
end

button.MouseEnter:connect(function()
    mouseIn(button, hintText, hintPos)
end)
button.MouseLeave:connect(function()
    mouseOut(button)
end)

I create a table called hoverBtns. It is used as a dictionary to contain buttons that are in the hover state. In the mouseIn() function, I set the properties on my hint and add the button to the hoverBtns table. In the mouseOut() function, I remove the button from the hoverBtns table, then do a check to see if hoverBtns is empty. If it is, I hide the button.

What is happening?

In my case, when moving the mouse from one button to another, the mouseOut event of button1 was being handled AFTER the mouseIn event of button2. So the mouseIn event of button2 would fire and place the hint where it was supposed to be near button2, then the mouseOut event of button1 would fire, which would hide the hint.

This solution uses the hoverBtns table to determine whether or not to actually hide the hint. If there is still a button in the table, a button is being hovered, so don't hide the hint.

Good luck! I hope you are able to use my example to overcome the difficulty you are having.

Ad

Answer this question