I need to make this loading script work. For some reason it is always two off, example the assets * is set to 100 it will only go to 98 and then get stuck. This is the code
--//Services\\--
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local LoadingGui = script:WaitForChild("Loading")
local Assets = game:GetDescendants()
local ClonedLoadingScreen = LoadingGui:Clone()
ClonedLoadingScreen.Parent = PlayerGui
local Percentage = ClonedLoadingScreen.LoadingFrame.LoadingBar:WaitForChild("Percentage")
local LoadingBar = ClonedLoadingScreen.LoadingFrame:WaitForChild("LoadingBar")
--//Functions\\--
ReplicatedFirst:RemoveDefaultLoadingScreen()
TweenService:Create(ClonedLoadingScreen.LoadingFrame:WaitForChild("Icon"),
TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0),
{Position = ClonedLoadingScreen.LoadingFrame:WaitForChild("Icon").Position - UDim2.new(0,0,0.1,0)}):Play()
TweenService:Create(ClonedLoadingScreen.LoadingFrame:WaitForChild("Pattern"),
TweenInfo.new(30, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, true, 0.2),
{Position = ClonedLoadingScreen.LoadingFrame:WaitForChild("Pattern").Position + UDim2.new(0.7,0,0.7,0)}):Play()
for i = 1, #Assets do
local asset = Assets[i]
local percentage = math.round(i / #Assets * 100)
ContentProvider:PreloadAsync({asset})
Percentage.Text = percentage.."/100%"
TweenService:Create(LoadingBar.Bar, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percentage/100, 1)}):Play()
if i % 3 == 0 then
task.wait()
end
if i == #Assets then
task.wait(1)
game:GetService("SoundService"):WaitForChild("Main"):WaitForChild("Interface"):FindFirstChild("LoadingSound"):Play()
end
end
for i, loadingassets in pairs(ClonedLoadingScreen:GetDescendants()) do
if loadingassets:IsA("Frame") then
TweenService:Create(loadingassets, TweenInfo.new(0.3, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
elseif loadingassets:IsA("TextLabel") then
TweenService:Create(loadingassets, TweenInfo.new(0.3, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
elseif loadingassets:IsA("ImageLabel") then
TweenService:Create(loadingassets, TweenInfo.new(0.3, Enum.EasingStyle.Linear), {ImageTransparency = 1}):Play()
elseif loadingassets:IsA("UIStroke") then
TweenService:Create(loadingassets, TweenInfo.new(0.3, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
end
end
task.wait(.5)
LoadingGui:Destroy()