I keep get the error “Can only tween objects in the workspace” when tween a frame using :TweenSize()

Hello, I’m using :TweenSize to animate the size of a Image Button in my game, but whenever I use :TweenSize it gives me the error:

“Can only tween objects in the workspace”

Is there a way I could fix this?

If it helps, here is my script:

				PopupGui.InteractionFrame.InteractButton:TweenSize(
					UDim2.new(1.25, 0,1.25, 0),
					"Out",
					"Quad",
					.1,
					true
				)	

Were the button is:
Screenshot 2023-02-08 163556

Try using TweenSevice instead

A Couple of things:

  • Make sure you are getting the GUI you want

  • Make Sure the GUI is properly Loaded

  • Make sure the GUI is properly Parented as the GUI can be Parented to nil

so make sure you at least use WaitForChild() to wait for the GUI to load Properly:

local UI = PopupGui:WaitForChild("InteractionFrame"):WaitForChild("InteractButton")
UI:TweenPosition(UDim2.fromScale(1.3,1.3), "InOut", "Sine", 2)

However yes, like @Dede_4242 said, Its better to use TweenService over the Tween functions as they provide more functionality than they could, which they are practically Deprecated.

Using this code, I don’t get a error but it does not tween:

				local targetSize = UDim2.new(1.3, 0,1.3, 0)

				local tweenInfo = TweenInfo.new(2)
				local tween = TweenService:Create(PopupGui.InteractionFrame.InteractButton, tweenInfo, {Size = targetSize})

				tween:Play()

What I think is wired is that it tweens perfectly fine with the same code in the same script using :TweenSize, Could the issue be that it is in a function?

@MasonX890 It isnt the function, but the Instance you are trying to Tween

So I made sure to test if the Parent to nil would error and yes:

script.Parent.Parent = nil -- sets Parent to nil (Doesnt Delete it)
script.Parent:TweenPosition(UDim2.fromScale(1,1), "In" ,"Sine", 10) -- error line

It gives the exact error: Can only tween objects in the workspace
So you should Probably make sure that the UI you are trying to tween is properly loaded or within the Correct Parent.