Loading Screen not working/functioning

I have been trying to make a loading screen on Roblox which loads assets and displays a % on a loading a bar. It also replaces the default screen,
The script and screen are within ReplicatedFirst
The issue is that the bar/assets and the percentage are simply not changing.

I have tried looking for solutions on the forums and hub with little to no help.
This is the code ;

local replicatedfirst = game:GetService("ReplicatedFirst")
local contentprovider = game:GetService("ContentProvider")
local tweenservice = game:GetService("TweenService")
local players = game:GetService("Players")

local player = players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local loadingscreen = script:WaitForChild("LoadingScreen")


local assets = game:GetDescendants()
local clonedLoadingScreen = loadingscreen:clone()
clonedLoadingScreen.Parent = playergui

for i = 1, #assets do
	local asset = assets[i]
	local percentage = math.round(i / assets * 100)
	clonedLoadingScreen.Background.DisplayPercentage.Text = percentage.."%"
	clonedLoadingScreen.Background.DisplayAssetsLoaded.Text = "Loading Assets: "..i.."/"..#assets
	tweenservice:Create(clonedLoadingScreen.Background.BarBackground.Bar.Size, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, {Size = UDim2.fromScale(percentage/100)}))
	if i % 5 == 0 then
	if i == #assets then

1 Like

It looks like your local percentage variable is the problem, in the i / assets you are calling the array, not the size of the array, all you would need to do is change assets to # assets, at least I am pretty sure calling assets and not # assets is causing this problem, otherwise I don’t really see any other issues atm.

local percentage = math.round(i / #assets * 100)

Did that, nothing changed :frowning:
I am not exactly sure what is wrong in the code. It could be the organization of the items too.
Haven’t been able to narrow down the issue

1 Like

After looking at it again it appears you forgot to add :Play() for the tweenservice, unless you have that somewhere else.

tweenservice:Create(clonedLoadingScreen.Background.BarBackground.Bar.Size, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, {Size = UDim2.fromScale(percentage/100)})):Play()

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