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

Help with MouseHover on textbutton?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

This is what is happening: https://gyazo.com/b0f67e1f5069c4ef000ca2a178992b33 I don't want that to happen, there are NO errors of course.

PlayButton.MouseEnter:connect(function()
    if PlayButton:FindFirstChild('Background') then
        for i = 0,1,.05 do
            PlayButton:WaitForChild('Background').Size = UDim2.new(i, 0, 1, 0)
            wait()
        end
    end
end)

PlayButton.MouseLeave:connect(function()
    if PlayButton:FindFirstChild('Background') then
        for i = 1,0,-.05 do
            PlayButton:WaitForChild('Background').Size = UDim2.new(i, 0, 1, 0)
            wait()
        end
    end
end)

1 answer

Log in to vote
1
Answered by
AZDev 590 Moderation Voter
8 years ago
-- Bool to check if mouse enters or leaves.

local isHovering = false

PlayButton.MouseEnter:connect(function()
    isHovering = true
    if PlayButton:FindFirstChild('Background') then
            for i = 0,1,.05 do
            if not isHovering then break end -- If the player stop hovering stop loop
                    PlayButton:WaitForChild('Background').Size = UDim2.new(i, 0, 1, 0)
                wait()
             end
        end
end)

PlayButton.MouseLeave:connect(function()
    isHovering = false
    if PlayButton:FindFirstChild('Background') then
        for i = 1,0,-.05 do
        if isHovering then break end
                PlayButton:WaitForChild('Background').Size = UDim2.new(i, 0, 1, 0)
                wait()
        end
    end
end)

Ad

Answer this question