mouseHover and mouseLeave not working as intended

In the clip whenever I unhover from the buttons some of them will stay in the hovered position and I have no idea how to fix this. I have literally tried everything I could, I tried running a while true do to check if the player is not hovering over them then to set Scale to 1 but that didn’t work, I tried to make a table of when they hover it will save that button and then if they try to hover while in progress it won’t let them, but somehow it bypasses my code and I am hardstuck on what to do. Here is the code I tried:

function TWEEN.mouseHover(obj)
	if not obj or tweensInProgress[obj] == true then return end
	local UiScale = obj.UIScale
	
	tweensInProgress[obj] = true
	
	local t = TS:Create(UiScale, TWEEN.infoForTween, {Scale = 1.1})
	t:Play()
	t.Completed:Wait()
	tweensInProgress[obj] = false
end

function TWEEN.mouseLeave(obj)
	if not obj or tweensInProgress[obj] == true then return end
	
	local UiScale = obj.UIScale

	tweensInProgress[obj] = true

	local t = TS:Create(UiScale, TWEEN.infoForTween, {Scale = 1})
	t:Play()
	t.Completed:Wait()
	tweensInProgress[obj] = false
end

If anyone has an idea on how to make this work when the player hovers over a bunch at a time it would be appreciated.

2 Likes

Use this function instead

game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(mouse.X, mouse.Y)

Then run this under a runservice loop, the code above will return a table with all gui elements in the table.

1 Like

You’re overlapping tweens and because tweens can’t be changed once played, the size isn’t set to the one you want. Seeing you have a tweensInProgress table, if a tween on the object is playing, cancel it and then play the new tween

How would I check if the current tween playing and if the player hovers over a new button.

Would I just make the tweenInProgress[obj] = t?? im a bit confused

Instead of doing tweenInProgress[obj] = true, store the actual tween like this:

local objectTween = TS:Create(UiScale, TWEEN.infoForTween, {Scale = 1})
tweenInProgress[obj] = objectTween

And then to check if a tween exists on the object and cancel it, do this:

if tweenInProgress[obj] then
    tweenInProgress[obj]:Cancel()
    tweenInProgress[obj] = nil
end

But if I set the obj to the tween and check after its just gonna cancel the tween out

Yes that’s what you want, to cancel out the old tween and replace it with the new one. Because right now they are overlapping.

function IconUX.ShrinkOnGuiStateChange(providedFrames : typeof({}))
	
	for i, frame in providedFrames do
		frame:GetPropertyChangedSignal("GuiState"):Connect(function()
			
			local currentMousePosition = UIS:GetMouseLocation()
			local hoveredObjects = PlayerGui:GetGuiObjectsAtPosition(currentMousePosition.X, currentMousePosition.Y)

			if table.find(hoveredObjects, frame) then
				return
			end

			task.wait(0.08)
			if frame.GuiState == Enum.GuiState.Idle then
				IconUX.Shrink(frame) -- Replace this whatever function you need
			end
		end)
	end
end

My module already checks for that, just add any frames you want and replace the shrink.
If you don’t plan on using this, then my only recommendation is not using an infinite loop, b/c that slightly loses performances while not necessary.

try this:

function TWEEN.mouseHover(obj)
	local UiScale = obj.UIScale
	
	if tweensInProgress[obj] and tweensInProgress[obj].PlaybackState == Enum.PlaybackState.Playing then
		tweensInProgress[obj]:Cancel()
	end
	
	local tween = TS:Create(UiScale, TWEEN.infoForTween, {Scale = 1.1})
	tweensInProgress[obj] = tween
	tweensInProgress[obj]:Play()
end

function TWEEN.mouseLeave(obj)	
	local UiScale = obj.UIScale

	if tweensInProgress[obj] and tweensInProgress[obj].PlaybackState == Enum.PlaybackState.Playing then
		tweensInProgress[obj]:Cancel()
	end

	local tween = TS:Create(UiScale, TWEEN.infoForTween, {Scale = 1})
	tweensInProgress[obj] = tween
	tweensInProgress[obj]:Play()
end

wait i found the issue i just had to write 4 lines of codes OMG

function TWEEN.mouseHover(obj)
	local t = TS:Create(obj.UIScale, TWEEN.infoForTween, {Scale = 1.1})
	t:Play()
end

function TWEEN.mouseLeave(obj)
	local t = TS:Create(obj.UIScale, TWEEN.infoForTween, {Scale = 1})
	t:Play()
end

IDK how this works but im not touching it so it works

2 Likes