How to use Udim2 to scale without a position change?

Hello!

I wanted to create a countdown UI like Game Rivals. To do this, I’m trying to tween TextLabel using Udim2, but if I use the code below to change the size, the text will move to the wrong place.

local TS = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Events = ReplicatedStorage:WaitForChild("Events")
local WaitTimeUpdate = Events:WaitForChild("WaitTimeUpdate")

local Intermission = script.Parent:WaitForChild("Intermission")
local TimerText = Intermission:WaitForChild("Timer")
local Glow = TimerText:FindFirstChild("Glow")

local TextTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential)
local TextTweenProperty = {Size = UDim2.new(1,0,1,0)}
local TimerTextTween = TS:Create(TimerText, TextTweenInfo, TextTweenProperty)

local GlowTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine)
local GlowTweenProperty = {ImageTransparency = 1}
local GlowTween = TS:Create(Glow, GlowTweenInfo, GlowTweenProperty)

local function TextEffect()
	TimerText.Size = UDim2.new(1.5,0,1.5,0)
	TimerTextTween:Play()
	Glow.ImageTransparency = 0.6
	GlowTween:Play()
end

WaitTimeUpdate.OnClientEvent:Connect(function(timer)
	TextEffect()
end)

To be honest, I haven’t fully understood the Ui concept like Udim2 yet. These elements were too difficult for a novice developer who wasn’t good at it.

I’ve read related documents, but it wasn’t easy to understand, maybe because it was inexperienced. Can you tell me how to use Udim2 to achieve what you want?

i feel like there’s Offset applied to your UI aswell, I’d recommend putting UIScale and tween the Scale property from there if using UDim2.fromScale() doesn’t affect anything.

1 Like

When it comes to ScreenGUI’s it’s best to size the UI by Scale. If you are trying to tween or change the size of a UI object and you don’t want it to change Position, you’d need to set the AnchorPoint property to the center of the UI object. In this case you’d need to set it to 0.5, 0.5.

1 Like

Thank you for your new idea! :heart:

I tried your solution but its not work :sob:
thank you for suggest the solution!

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