Any way to find "percentage of tween completed"?

I’m doing this for a loading bar and want to know if I can sync up my loading bar and my “Loading Assets - 0% done” text.

yes u can know the time of the tween, for example if u know ur tween lasts 2 seconds, then u can easilly represent that on bar

It’s not simple math, is it? I don’t have any percentages in the math program this year, but you could use fractions and convert them into percentages. You can use the size as reference, so for example local fraction = AktualSize/TotalSize and just convert this to a percentage. You can google.

1 Like

Well no, since it represents the amount of time it takes for all assets to load in…

How would I get the fraction completed then?

why would u like to tween unload assets, I dont get it

So all the assets are preloaded into the game before the player joins

you can do something like this

--GUIObject:TweenPosition(BlaBla, EasingDirection, EasingStyle, Time)
local CurrentTime = tick()
local percentage 

percentage = ((CurrentTime-tick()) / Time) * 100

If you want it in decimal form simply remove the * 100

Just make sure you keep updating the percentage value with that formula so it’s up to speed

I think this is a loading screen script:

script.Parent:RemoveDefaultLoadingScreen()


local loadingScreen = script.LoadingScreenGUI

loadingScreen.Parent = game.Players.LocalPlayer.PlayerGui


local contenProvider = game:GetService("ContentProvider")
game.Loaded:Wait()
local toLoad = workspace:GetDescendants()
local total = #toLoad
for i,v in pairs(toLoad) do
	loadingScreen.Background.Counter.Text = "Loading: " .. i .. "/" .. total .. " " .. v.Name
	loadingScreen.Background.BarBG.Bar.Size = UDim2.new(i/total, 0, 1, 0)
	contenProvider:PreloadAsync({v})
end


wait(1)
loadingScreen:Destroy()

Oh, yeah it is, my bad (30 chars)

Why not the GetPropertyChangedSignal function? So if the size stops to change it would stop the script.

Its only asking for getting a percentage, not how to make a LoadingScreenScript. Else it would first ask on how to make a LoadingScreen (but Youtube and other platforms are full with Roblox Tutorials) and then this here.

Ye that works too
(30 Characters)

1 Like

Ok so this is giving me an error:
local percent = tonumber(script.Parent.Loaded.Size.X) / 0.9 * 100
image
EDIT: maybe because it’s a UDim2

the tonumber is useless (in that scenario), and yes it’s because its udim, you need to index the scale or offset value.
script.Parent.Loaded.Size.X.Scale

2 Likes

Ok. That works but how can I remove all the decimals places, so it’s only a whole number? Sorry, never done something like this haha

1 Like

you use the math.floor() function
math.floor(script.Parent.Loaded.Size.X.Scale / 0.9 * 100)

1 Like

Thank you, works perfectly! @InternallyAmplified @Eternalove_fan32

2 Likes

Please never suggest pushing the entire workspace’s descendants through PreloadAsync. This diminishes the benefit of it and long loading screens are bad for UX.

PreloadAsync only deals in assets coming from CDNs (unions, meshes, textures, sounds, etc) and you should only be using it with things that need to be seen immediately. Anything else can be downloaded in the background. Preload is intended to prioritise downloading.

Also, long loading screens aren’t the best for impatient audiences, especially young players.

4 Likes