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

I need help with my tweens, I'm confused, and it's not working?

Ok, so as the title says, my tweens aren't working. To be more specific, I'm trying to tween the SliceScale of an image. I'm using Instance:TweenSize() to try and tween the scale, but it's not working and erroring "ApplicationUI.AppBody.Applications.1.ButtonSqueeze:5: attempt to index number with 'TweenSize'". I'm not sure what I did wrong, please help.

Here is my code:

local Icon = script.Parent

Icon.MouseEnter:Connect(function(Entered)
	Icon.ImageColor3 = Color3.fromRGB(3, 146, 255)
	Icon.SliceScale:TweenSize(0.25)
end)

Icon.MouseLeave:Connect(function(Left)
	Icon.ImageColor3 = Color3.fromRGB(0, 170, 255)
	Icon.SliceScale:TweenSize(0.1)
end)

2 answers

✓ Accepted answer

Pointing out some issues:

Let's begin with the call of the TweenSize method. This function belongs to the abstract GUIObject class, meaning it's only invokable from an Instance of said class; you're halfway there, though, you've attempted to derive it from a property.

The method alone requires a total of six arguments, with one mandatory: the UDim2 final—which we can construct in-line.

Let's see how this would've looked:

Icon:TweenSize(UDim2.new(0, 0, 0, 0))

Addressing the problem:

The TweenSize method of GUIObject is designed to do just that, "tween" it's size. Though, from the looks of it, you appear to be trying to smoothly adjust a property. To achieve this, we have to take a different approach with TweenService.

To construct a specialized Tween designed to adjust a property, we have to build a customized tween-object with the Create function.

This function requires three mandatory arguments, that of which are:

TweenService:Create(
	The object we're tweening, 
	The details of said tween, 
	The properties to adjust
)

To provide the tween details, we use a TweenInfo Object; click the hyperlink to learn which details are assignable, and what each argument represents.


Bringing it all together:

local TweenService = game:GetService("TweenService")

local TweenDetails = TweenInfo.new(1) --// Time-length


local Icon = script.Parent


local TweenEnter = TweenService:Create(Icon, TweenDetails, {SliceScale = 0.25})
local TweenLeave = TweenService:Create(Icon, TweenDetails, {SliceScale = 0.1})

Icon.MouseEnter:Connect(function()
	TweenEnter:Play()
end)

Icon.MouseLeave:Connect(function()
	TweenLeave:Play()
end)

2 comments

0

This is probably the best answer you could have given! I understand that TweenSize uses UDim2, but I thought you could just use it without it for instances like this. I also thought about using TweenService, but I didn't know how, and this mini-tutorial helped a lot! Again, thank you!

0

Glad I could help!

:TweenSize() is used to scale UDim2 data or an object (as it is a function of an object, see documentation) but you are trying to apply it to a single number which is a property.

...Using Tween:Create() will let you tween properties! :) (hope this is right Feahren lol)

Let me know if this helped! :) Good luck!

Thanks @Feahren

1 comment

0

Thank you for your response!

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