UDim2 Not Working Properly

Hello! So I’m using TweenSize, and for some reason, UDim2 isn’t working as intended. Here’s my code, (Sorry for the terrible formatting, you can edit it if you’d like), can anyone help?

repeat
	task.wait(1)
until game:IsLoaded()

local delta_time = 0.04
for i = 1, 100 do
	task.wait(delta_time)
	local formula = i/100
	
	script.Parent:TweenSize(UDim2.new(0, formula, 0, 25), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, false)
	
	if i == 34 then
		task.wait(0.04)
		script.Parent.Parent.Parent.TextComponents.TextLabel.Text = "🌴 Have you explored all the worlds?"
	elseif i == 67 then
		task.wait(0.04)
		script.Parent.Parent.Parent.TextComponents.TextLabel.Text = "🐠 Join our Discord community!"
	elseif i == 91 then
		task.wait(0.04)
		delta_time = 0.02
		script.Parent.Parent.Parent.TextComponents.TextLabel.Text = "🐦 @Cloudbot"
	end
end

local tween = game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false, 0), {Position = UDim2.new(0.5, 0, 1.2, 0)})
local tween2 = game:GetService("TweenService"):Create(script.Parent.Parent, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false, 0), {Position = UDim2.new(0.5, 0, 1.2, 0)})
local t1 = game:GetService("TweenService"):Create(script.Parent.Parent.Parent.TextComponents.TextLabel, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0), {TextTransparency = 1})
t1:Play()
t1.Completed:Wait()
tween2:Play()
tween:Play()
tween.Completed:Wait()
local t = game:GetService("TweenService"):Create(script.Parent.Parent.Parent, TweenInfo.new(0.6, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0.5), {BackgroundTransparency = 1})
local t2 = game:GetService("TweenService"):Create(script.Parent.Parent.Parent, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0.5), {Position = UDim2.new(0.499, 0, 0.639, 0)})
local t3 = game:GetService("TweenService"):Create(script.Parent.Parent.Parent.ImageLabel, TweenInfo.new(0.7, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false, 0), {Position = UDim2.new(0.5, 0, 1.7, 0)})
t3:Play()
t:Play()
t.Completed:Wait()
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
script.Parent.Parent.Parent.Parent:Destroy()

So it looks like I’d work, except for some reason, part 2 of the UDim2 isn’t working and doesn’t error. Let me know if you need any extra info!

I’m not sure if it’s me, but could you express what exactly is wrong, it’s hard to provide any support if I do not understand what the snippet is intended to do.

Basically, it’s a loading bar. The second condition in the UDim2 isn’t working properly, but when I switch it with the first one, it offsets it a lot, but works fine.

To then clarify further, it’s this specific line right here?

script.Parent:TweenSize(UDim2.new(0, formula, 0, 25), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, false)

Yes! That’s the exact line, sorry for not stating that before.

.

image
you cant put a decimal on the offset, make it to
Udim2.new(formula, 0, 0, 25)

Correct, as offset is considered a pixel measurement and not a % or scale of the parent box.

1 Like

True, and I do notice. However, that messes the entire thing up, so that’s not an option. Right now, I’m trying UDim.fromOffset and UDim.fromScale, to find a solution out of one of them. I believe I found one, give me a moment.

i recommend using fromScale instead of fromOffset because if offset, in small device such as mobile, it will just overlap the UI.

so i assume that its not working because you didn’t make it

→ Frame1 (How big you want the loading is)
→→ Frame2 (Where you size the UI to generate the loading size.)[Parent:Frame1]

and also if your using offset, don’t use i/100 it will just give you a decimal number until 99

Nope, I did actually make it! (Used a tutorial for the formula though.)

Really? Because last I checked, the loop goes through 100, and it’s dividing i by 100…


100 is the only number on your for loop that its giving a non decimal number

The incremental value for what the outcome should be is exactly as intended. It’s just UDim2 is not working with what it gets, which is the problem. I’ve tried UDim2.fromScale, and UDim2.fromOffset countless times, and get the same product.

All you need to know is I need the slider to slide from the left to the right. What it’s doing right now is growing in the middle. Hopefully, that clears it up a bit more!

Is the element anchored on the left side?

1 Like

I just figured it out, it had something to do with the UI sizing/position itself. Thanks for the help, everyone!

1 Like