My Tweenservice kinda not working

Hello Everyone, i hope you guys have a nice day!

So i was making tweenService on the button, i want it to look kinda “satisfying”
So i did but from line 68 the tween isnt make the button small.
Code:

local Tween = game:GetService("TweenService")
local Button = script.Parent
local Text =  script.Parent.TextLabel
local Image = script.Parent.ImageLabel
local IB = script.Parent.ImageButton

local Info = TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)

local Goals = {
	["Size"] = UDim2.new(0, 219, 0, 93)
}

local Goals2 = {
["Size"] = UDim2.new(0, 174, 0, 88)
}

local Goals3 = {
	["Size"] = UDim2.new(0, 90, 0, 103)
}

local Goals4 = {
	["Size"] = UDim2.new(0, 219, 0, 93)
}

local function playTween()
	local ButtonS = Tween:Create(Button, Info, Goals)
	local TextS = Tween:Create(Text, Info, Goals2)
	local ImageS = Tween:Create(Image, Info, Goals3)
	local IBS = Tween:Create(IB, Info, Goals4)
	task.wait(0.1)
	ButtonS:Play()
	TextS:Play()
	ImageS:Play()
	IBS:Play()
end

Button.MouseEnter:Connect(playTween)

local Info2 = TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)

local GoalsS = {
	["Size"] = UDim2.new(0, 209, 0, 82)
}
local GoalsS2 = {
	["Size"] = UDim2.new(0, 153, 0, 78)
}
local GoalsS3 = {
	["Size"] = UDim2.new(0, 80, 0, 87)
}
local GoalsS4 = {
	["Size"] = UDim2.new(0, 209, 0, 82)
}
local function playTween2()
	local ButtonS = Tween:Create(Button, Info2, GoalsS)
	local TextS = Tween:Create(Text, Info2, GoalsS2)
	local ImageS = Tween:Create(Image, Info2, GoalsS3)
	local IBS = Tween:Create(IB, Info2, GoalsS4)
	task.wait(0.1)
	ButtonS:Play()
	TextS:Play()
	ImageS:Play()
	IBS:Play()
end


Button.MouseLeave:Connect(playTween2)

local Info3 = TweenInfo.new(0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)

local GoalsSS = {
	["Size"] = UDim2.new(0, 189, 0, 72)
}
local GoalsSS2 = {
	["Size"] = UDim2.new(0, 133, 0, 78)
}
local GoalsSS3 = {
	["Size"] = UDim2.new(0, 75, 0, 80)
}
local GoalsSS4 = {
	["Size"] = UDim2.new(0, 189, 0, 72)
}
local function playTween3()
	local ButtonS = Tween:Create(Button, Info3, GoalsSS)
	local TextS = Tween:Create(Text, Info3, GoalsSS2)
	local ImageS = Tween:Create(Image, Info3, GoalsSS3)
	local IBS = Tween:Create(Image, Info3, GoalsSS4)
	task.wait(0.01)
	ButtonS:Play()
	TextS:Play()
	ImageS:Play()
	IBS:Play()
end


Button.MouseButton1Click:Connect(playTween3)

and here is the footage:

this is what it should do:

2 Likes

Forgot to post that
image

1 Like

What exactly is the issue here? Are the elements in the button supposed to scale the same amount?

1 Like

The issue is, when i click the button, the button + Image label + etc doesnt change their sizes

1 Like

Have you tried altering the time parameter of Info3? Also, in my opinion, isn’t the shrinking supposed to happen when you hold the button and stop when you release it? Or is your design different?

1 Like

Thats what i am trying to do


Something like this
(Without turning the button into dark)

Then instead of Button.MouseButton1Click you should use Button.MouseButton1Down and Button.MouseButton1Up events.

Did you get the mouse of the player so that it detects when the player mouse hovers over the ui?

So i change the Button.MouseButton1Click to Button.MouseButton1Down and i add Button.MouseButton1Up?

sorry for asking to many questions because i am new into scripting

Yes it does, it detects when the player hover the mouse on the ui

Yes. Button.MouseButton1Up should handle the button after the player has released the button.

There is a lot of issues that may not be a problem now but they will be in the future, First is the Scaling, you are changing the offset instead of the scale: Udim2.new(ScaleX,OffsetX,ScaleY,OffsetY), this can cause users to have bad ui button placements, another issue is the tweening, you should just scale the Script.Parent button, since everything else inside of it will scale aswell.

1 Like

“Click” should be used for what the button does. example: open the settings menu
“Down” play the tween to make it smaller
“Up” play the tween to make it normal again

i tried scaling the Button it self and everything was messed up


hopefully i understood what you meant

Also, why you have task.wait() with so low numbers like 0.1 or 0.01, unless you want some delay in it, you should just leave it empty or remove it entirely

So i should change
Button.MouseLeave:Connect(playTween2)Button.MouseButton1Up:Connect(playTween2)
and
Button.MouseButton1Click:Connect(playTween3) —> Button.MouseButton1Down:Connect(playTween3)
something like that?

Here a plugin to help with it!

1 Like

Yes, but depending on the result you want you may have to use MouseEnter and MouseLeave

No make a player variable and get the Mouse

local TS = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local UiButton = script.Parent

UiButton.MouseEntered:Connect(function()
--Play the TweenService when the mouse hovers the Button
end

UiButton.MouseLeave:Connect(function()
--Reset the CFRAME of the Ui when the mouse is no longer on the UiButton
end

In your code you don’t actually use plrMouse. Why is that?