What's wrong with this module?

Hello, I have been working on a UI animation module but it has a problem where this always happens:


It always scales the entire UI down to a really small size no matter what facor you send when calling the function here is my code:

local module = {}

local tweenService = game:GetService('TweenService')

local cdSize = false
local cdRotation = false

function module.Shrink(element, Factor, Speed)
    if not cdSize then
        cdSize = true
        local ScaleX = element.Size.X.Scale*Factor
        local ScaleY = element.Size.Y.Scale*Factor

        local sizeInfo = TweenInfo.new(
            Speed,
            Enum.EasingStyle.Sine,
            Enum.EasingDirection.InOut,
            0,
            true,
            0
        )


        local SizeTween = tweenService:Create(element, sizeInfo, {Size = UDim2.new(ScaleX, ScaleY)})

        SizeTween:Play()
        wait(3)
        cdSize = false
    end

end

function module.Rotate(element, Factor, Speed)
    if not cdRotation then
        cdRotation = true

        local RotationInfo = TweenInfo.new(
            Speed,
            Enum.EasingStyle.Sine,
            Enum.EasingDirection.InOut,
            0,
            true,
            0
        )
        
        local RotationTween = tweenService:Create(element, RotationInfo, {Rotation = Factor})

        RotationTween:Play()
        wait(3)
        cdSize = false
    end
end

return module

The local script:

local module = require(game.ReplicatedStorage.Modules.UIAnimation)


script.Parent.MouseButton1Click:Connect(function()
    module.Shrink(script.Parent, .5, .2)
end)


script.Parent.MouseEnter:Connect(function()
    module.Rotate(script.Parent, 3,.1)
end)

Thank you!

{Size = UDim2.new(ScaleX, ScaleY)}

Is your issue, UDim2 are constructed like this, ScaleX, OffsetX, ScaleY, OffsetY, it treats ScaleY as the Offset of X

Fix?

Do this

{Size = UDim2.new(ScaleX,0, ScaleY,0)}
1 Like

Thanks again! It works really well!

1 Like

Anytime! Make sure you remember this so you don’t this mistake again in the future haha. If you have anymore issues don’t be afraid to make another post!

1 Like