Invalid argument #2 (UDim expected, got number) How do I fix?

I rechecked the parameters for tweening, they seem to be correct I can’t seem to find a solution any suggestions?

Error: on line 11

Code:

local gui = script.Parent.Parent
local frame = script.Parent
local slider = frame.slider
local page = frame.page 

for i,object in pairs(frame:GetChildren()) do 
	if object:IsA("TextButton") then
		object.Text = object.Name
		
		object.MouseButton1Click:Connect(function()
           -- Error below ↓
			slider:TweenPosition(UDim2.new(object.Position.X, object.Position.Y + 0.026),Enum.EasingDirection.Out, Enum.EasingStyle.Elastic,0.5,true)
		end)
	end
end

Thanks in advance.

3 Likes

Look at the documentation more carefully. I assume you want to use the offset, in which case you would use:

UDim2.fromOffset(object.Position.X, object.Position.Y + 0.026)

The output prints the same error, “invalid argument #2 (UDim expected, got number)”, whether it is UDim2.fromOffset or UDim2.fromScale (which I am utilizing).

That’s odd, can you show the current code you have?

local gui = script.Parent.Parent
local frame = script.Parent
local slider = frame.slider
local page = frame.page 

for i,object in pairs(frame:GetChildren()) do 
	if object:IsA("TextButton") then
		object.Text = object.Name
		
		object.MouseButton1Click:Connect(function()
			slider:TweenPosition(UDim2.fromScale(object.Position.X, object.Position.Y + 0.026),Enum.EasingDirection.Out, Enum.EasingStyle.Elastic,0.5,true)
		end)
	end
end

Error, Line 11
invalid argument #2 (UDim expected, got number)

I figured out the solution when I tried to add 0.026 to the Y position I was trying to add it to both values of Y, scale, and offset so instead I wrote. object.Position.Y.Scale to get add the scale value.

10 Likes