Need a bit of help with not being able to perform arithmetic on UDim2

I am getting an error while trying to tween a gui 1.5x more.

I just need to fix the error:

attempt to perform arithmetic (mul) on UDim and number

I tried a bunch of stuff like using Vector2’s and other modifiers. But none worked

For a bit more context, im trying to make a script (that is done) that I can paste into any object to have animations play on hover over and click

local open = script.Parent
local dPosX = open.Size.X
local dPosY = open.Size.Y

open.AnchorPoint = Vector2.new(0.5,0.5)

open.MouseEnter:Connect(function()
	open.Size = UDim2.new(dPosX,0,dPosY,0)
	open:TweenSize(Vector2.new(open.Size.X * 1.5,open.Size.Y * 1.5), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.1)
end)

open.MouseLeave:Connect(function()
	open:TweenSize(Vector2.new(open.Size.X * -1.5, open.Size.Y * -1.5), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.1)
	wait(0.2)
	open.Size = UDim2.new(dPosX,0,dPosY,0)
end)

thats my code!

1 Like

I don’t really understand the code but I prefer using variables example:

local open = script.Parent
local TweenService = game:GetService("TweenService")
local MainTweeningInformation = TweenInfo.new(
    TIMEHERE,
    Enum.EasingStyle.Quint,
    Enum.EasingDirection.Out,
    0.1
)

local OpenGoal = {
    Size = UDim2.new(SIZEHERE)
}

local CloseGoal = {
    Size = UDim2.new(SIZEHERE)
}

local Open = TweenService:Create(open, MainTweeningInformation, OpenGoal)
local Close = TweenService:Create(open, MainTweeningInformation, CloseGoal)

open.MouseEnter:Connect(function()
    Open:Play()
end)

open.MouseLeave:Connect(function()
    Close:Play()
    wait(0.2)
    open.Size = UDim2.new(SIZEHERE)
end)

When you’re getting open.Size.X/Y you’re getting both Scalar and Offset
instead of vector2 do UDim2.new(open .Size.X.Scale * 1.5,0,open.Size.Y.Scale*1.5,0)
Also use TweenService Create over TweenSize/Position.
ex:

local myTween = TweenService:Create(open,TweenInfo.new(0.2),{Size = UDim2.new(open .Size.X.Scale * 1.5,0,open.Size.Y.Scale*1.5,0)})
myTween:Play()

https://developer.roblox.com/en-us/api-reference/function/TweenService/Create

Oh wait I didn’t see Vector2 lol.

I meant to use UDim2.new so yeah

Ill try that but im still not sure about the create part lol

For some reason it makes the gui disappear

Size.X gives you an UDim2 value that has both scale and offset, use X.Offset or X.Scale instead
Also since your tween will always end up at a specific point you dont need to define open.Size again.

local open = script.Parent
local dPosX = open.Size.X.Offset
local dPosY = open.Size.Y.Offset

open.AnchorPoint = Vector2.new(0.5,0.5) -- maybe you should just set the anchorpoint manually, no need to put this in a script unless you are changing it.

open.MouseEnter:Connect(function()
	open:TweenSize(Vector2.new(dPosX   * 1.5,dPosY * 1.5), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.1)
end)

open.MouseLeave:Connect(function()
	open:TweenSize(Vector2.new(dPosX  * -1.5, dPosY * -1.5), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.1)
end)

A 1.5 multiplier means you’re increasing its size by your screens entire resolution almost twice.
I recommend you resize your UI to what you want it to be as in studio mode and then changing the udim2 values to what you have.