I know how to use tween, but am so confused as to how to make the text smooth as well, please help me out

Yo, so I am trying to make this smooth animation, and am using the same code to animate both the button and text, I want to make them both smooth, but the text is unbelievably choppy, anyone have any ideas?

Hierarchy:

Video:

Code:

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local button = script.Parent
local label = button:WaitForChild("Text")

local baseSize = button.Size
local baseLabelSize = label.Size

local pulseAmplitude = 0.08
local pulseSpeed = 1.5
local hovering = false
local pulsing = false
local clickedWhileHovering = false
local startTime = 0

local clickScale = 0.92
local tweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local function precise(val, decimals)
	local mult = 10 ^ decimals
	return math.floor(val * mult + 0.5) / mult
end

local function getScale(t)
	local sineValue = math.sin(t * math.pi * pulseSpeed)
	local scale = 1 + sineValue * (pulseAmplitude / 2)
	return precise(scale, 9)
end

local function applyScale(scale, base)
	return UDim2.new(
		base.X.Scale * scale,
		base.X.Offset,
		base.Y.Scale * scale,
		base.Y.Offset
	)
end

local function tweenTo(scale)
	local goal = {
		Size = applyScale(scale, baseSize)
	}
	local labelGoal = {
		Size = applyScale(scale, baseLabelSize)
	}
	TweenService:Create(button, tweenInfo, goal):Play()
	TweenService:Create(label, tweenInfo, labelGoal):Play()
end

button.MouseEnter:Connect(function()
	hovering = true
	if not clickedWhileHovering then
		pulsing = true
		startTime = tick()
	end
end)

button.MouseLeave:Connect(function()
	hovering = false
	clickedWhileHovering = false
	pulsing = false
	button.Size = baseSize
	label.Size = baseLabelSize
end)

button.MouseButton1Down:Connect(function()
	pulsing = false
	clickedWhileHovering = true
	tweenTo(clickScale)
end)

button.MouseButton1Up:Connect(function()
	tweenTo(1)
end)

RunService.RenderStepped:Connect(function()
	if pulsing then
		local t = tick() - startTime
		local scale = getScale(t)
		button.Size = applyScale(scale, baseSize)
		label.Size = applyScale(scale, baseLabelSize)
	end
end)
3 Likes

You prob dont need to tween the text size just the textbutton or textlabel

I don’t use Text Size when doing this tween, I do the size of the textLabel, check Line 8:

local baseLabelSize = label.Size

But if there is a button with the text why dont you animate just the button and not the text aswell?
Since when the button gets animated the text should also get animated

Because the stagnent text with the moving button would look off, I understand your point, but the text needs to be animated, is there any way to smooth it down, I’m decent at math, im in Calc 1, just need a formula or idea to go by.

Hey i am sorry i am not that advanced i tried finding ways to help but i just couldnt find anything i am sorry i hope you will find your solution soon

That’s alright, I will just have to wait and see if anyone can find something for me to do in order to fix my problem, thanks for the help :smiley:

One thing you could try is putting it inside of a CanvasGroup and resize the CanvasGroup instead of the elements inside it.

Alright, I’ll do that, I should get back to you soon.

:frowning: That didn’t help, I tried everything, it hasn’t worked, I don’t think it’s possible, though I have a solution, I’ll just make an image of it, then scale it that way. Thanks for the help though, I’ll give you the solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.