Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with MouseHover on textbutton?

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

✓ Accepted answer
-- 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)

This discussion is preserved as it was. New answers, comments, and votes are closed.