What is wrong with my loading bar?

Hello,

I am trying to create a loading bar that works but for some reason it does never load. I believe this is due to game.Loaded:Wait(). For some reason when I put a print under it does not print out but when I do it above it does print.

If I am going around this the incorrect way could someone point me into the correct direction.

Code:

local contenProvider = game:GetService("ContentProvider")

local UI = script.Parent.Parent

local LoadingBar = script.Parent.BarBackground.Bar

local Skip = false

game.Loaded:Wait()

local ThingsToLoad = workspace:GetDescendants()

local total = #ThingsToLoad

print(#ThingsToLoad)

script.Parent.Skip.MouseButton1Click:Connect(function()

Skip = true

end)

for i,v in pairs(ThingsToLoad) do

print(v)

if Skip == false then

LoadingBar.Size = UDim2.new(i/total, 0, 1, 0)

contenProvider:PreloadAsync({v})

else

UI.Enabled = false

break

end

end

wait(1)

UI.Enabled = false

the thing is it only checks if skip is true once and thats when it loads in, make it so when u click the skip button the script removes the ui and it self

Um no it checks it everytime it goes through a object…

image

Also like I said I think there is an issue with the game.Loaded:Wait()

game.Loaded:Wait() might be yielding until the game is loaded, try printing the value for skip ever asset loaded and when u click the skip button

I mean that is what game.Loaded:Wait() does but I believe the game does load fully…

It does not print, I have already tried.

if the skip button doesnt even change the skip value then idk how to help but if it works try to just add the entire gui and script to debris with game:GetService(“Debris”):AddItem(gui,0)

gtg now but good luck!