TweenSize Issue

Hey everyone,
I recently started messing with tweens and I came across a problem with TweenSizing, I’d really appreciate if someone can tell me what I’m doing wrong:
https://gyazo.com/0763899e9679cb3506c7c848fdcd1d1f

I want to achieve a smooth animation every time the mouse enters and leaves the frame, like this:
https://gyazo.com/41f288163a05ddf31aa67d29566a9126

I know the issue is dealing with the mouse coming in and out of the frame too fast, not giving the animation enough time to finish (correct me if I’m wrong). I tried creating debounces and adding waits but none of that seemed to fix it.

Here’s the local script code:

local playerGui = player:FindFirstChild("PlayerGui")
local shopTimerText = script.Parent.layout.shopResetFrame.shopResetTimer.Text
local charBox1 = script.Parent.layout.charBox1
local pos1 = UDim2.new(0.1,0,0.204,0)
local pos2 = UDim2.new(0.275,0,0.204,0)
local pos3 = UDim2.new(0.45,0,0.204,0)
local deb = false
local deb2 = false

function mouseEnter1()
	if deb == false then
		deb = true
		charBox1:TweenSize(charBox1.Size + UDim2.new(0.015,0,0.05,0), "In", "Quad", 0.25)
		deb = false
	end
end

function mouseLeave1()
	if deb2 == false then
		deb2 = true
		charBox1:TweenSize(charBox1.Size - UDim2.new(0.015,0,0.05,0), "Out", "Quad", 0.25)
		deb2 = false
	end
end

charBox1.MouseEnter:Connect(mouseEnter1)
charBox1.MouseLeave:Connect(mouseLeave1)

This is probably happening because you’re creating a new UDim2 to tween to based on it’s current Size while it may be tweening.

I recommend creating a size that it tweens up/down to which isn’t changed.

local up = charBox1.Size + UDim2.new(0.015,0,0.05,0)
local down = charBox1.Size - UDim2.new(0.015,0,0.05,0)

--Then when tweening
charBox1:TweenSize(up, "In", "Quad", 0.25)
charBox1:TweenSize(down, "In", "Quad", 0.25)

Also, MouseEnter/MouseLeave is unreliable therefore I recommend using this module:

4 Likes

you are creating the size based on size, so every manipulation with size will afect this line and the manipulation will be relative so replace

by

box1normalsize - Udim.new(0.015,0,0.05,0)

and on top add

local box1normalsize = charBox1.Size

so the size in var will be fixed and you can freely change the real size

1 Like