Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TweenSizeAndPosition doesn't work? (argument 2 missing or nil)

So I made an image Button and whenever you click it a menu is supposed to pop up but I am getting an error saying (argument 2 missing or nill)

Here is my code

local menuButton = script.Parent
local mainMenu = script.Parent.Parent.MenuFrame.mainMenuFrame
local Tween = game:GetService("TweenService")

menuButton.MouseButton1Up:Connect(function()
	
	mainMenu:TweenSizeAndPosition{
		UDim2.new(0, 479,0, 271),
		UDim2.new(-7.792, 0,-0.742, 0),
		Enum.EasingStyle.Quint,
		Enum.EasingDirection.Out,
		1,
		false
		}

	
	
end)

Please tell me what I missed or what i'm doing wrong.

2 comments

0

Don't use brackets, use parentheses. Just a tip, not sure if that'll fix it or not. But in my opinion I'd use parentheses.

0

I changed them to parentheses and got a new error "Unable to cast token to token". Btw I use parentheses for variables and other stuff and brackets for tables, in this case i'm listing multiple things so I used brackets for a table.

2 answers

✓ Accepted answer

So basically I had easing direction and easing style the wrong way around.

Easing Direction comes first then Easing style comes second.

I had Easing Style first and Easing Direction Second that's why it wasn't working, this is how it is supposed to look.

local menuButton = script.Parent
local mainMenu = script.Parent.Parent.MenuFrame.mainMenuFrame
local Tween = game:GetService("TweenService")

menuButton.MouseButton1Up:Connect(function()

    mainMenu:TweenSizeAndPosition{
        UDim2.new(0, 479,0, 271),
        UDim2.new(-7.792, 0,-0.742, 0),
        Enum.EasingDirection.Out,
        Enum.EasingStyle.Quint,
        1,
        false
        }



end)

So, first off, just like Killerbrenden said in his comment, you need to make the brackets parentheses. It's in a tween function, not a table, you're listing the information that the tween needs in order to fire, it's not a table. This is also why you got a different error when you changed them.

Now, for second error, all you need to do is switch the EasingStyle and EasingDirection. In TweenSizeAndPosition, EasingDirection comes first. I changed your code, and this is what it's like with the changes:

local menuButton = script.Parent
local mainMenu = script.Parent.Frame
local Tween = game:GetService("TweenService")

menuButton.MouseButton1Up:Connect(function()
	mainMenu:TweenSizeAndPosition(
		UDim2.new(0, 479,0, 271),
		UDim2.new(-7.792, 0,-0.742, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quint,
		1,
		false
	)
end)

Also, when I tested it, it made the frame go off screen, so you'll need to change where it moves to. It could just be my screen, but I'm not entirely sure.

1 comment

0

Just refreshed the page after posting this answer, good work on finding it out yourself!

This discussion is preserved as it was. New answers, comments, and votes are closed.