Loading skip GUI button?

i’m back and need more help with things i got no clue how to do B)

So, I got my loading screen to function as intended, using the script from this post as a heavy base.
However, I also want to add in a skip loading button in the GUI, for the sake of my staff and just the general fact that you don’t have to load EVERYTHING in the game to play it.

For context, here’s how I’ve got these named + layered:
Screen Shot 2021-08-05 at 1.25.52 AM

I tried doing it via the simplest method I could think of, via putting a local script in the TextButton and basically doing:

local button = script.Parent
local gui = PlayerGui.LoadGui

button.MouseButton1Click:Connect(function()
   gui.Enabled == false

end)

This, of course, didn’t work. Doing some searching, I came upon this thread, which implements the skip button via pressing the spacebar, but notably puts the skip script into the loading GUI script itself.

It’s reliant on a break, which I’m not too sure how to work into my existing loading screen script.
Here is my script named “Loading”:

local ContentProvider = game:GetService("ContentProvider")

local toLoad = Workspace -- Replace workspace with what you need to load
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local Gui = script.Parent
local Bar = Gui:WaitForChild("Background"):WaitForChild("BarBackground"):WaitForChild("Bar")
local Text =  Gui:WaitForChild("Background"):WaitForChild("Text")
Gui.Enabled = true

for i = 1, totalAssets do
	pcall(function() -- You don't need pcall if you are not loading the whole game
		ContentProvider:PreloadAsync({assetsTable[i]})
		assetsLoaded = i
		Bar.Size = UDim2.new(i/totalAssets, 0, 1, 0)
		Text.Text = "Loading: " .. i .. " / " .. totalAssets .. " "
		print(assetsLoaded)
	end)
end

Text.Text = "Loaded!"

wait(2)

Gui.Enabled = false

print("All assets loaded.")

^ This works as intended. I just want to add a skip button that will close the GUI.

Help would be great. I’m just not too sure how to work it in, and I’ve tried a few ways, I just don’t really get what I’m doing either.

As always, I’m autistic, please be patient with me. I may need further explanation or things to be reworded so I can understand them.

2 Likes

This should work.

local ContentProvider = game:GetService("ContentProvider")

local toLoad = workspace -- Replace workspace with what you need to load
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local skipped = false

local Gui = script.Parent
local Bar = Gui:WaitForChild("Background"):WaitForChild("BarBackground"):WaitForChild("Bar")
local Text =  Gui:WaitForChild("Background"):WaitForChild("Text")
local SkipButton  = Gui:WaitForChild("Background"):WaitForChild("Skip")
Gui.Enabled = true

SkipButton.MouseButton1Click:Connect(function()
	skipped = true
end)

for i = 1, totalAssets do
	ContentProvider:PreloadAsync({assetsTable[i]})
	assetsLoaded = i
	Bar.Size = UDim2.new(i/totalAssets, 0, 1, 0)
	Text.Text = "Loading: " .. i .. " / " .. totalAssets .. " "
	print(assetsLoaded)
	if skipped then
		print("Skipped")
		local tweenTime = 0.2
		Bar:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, tweenTime)
		Text.Text = "Loaded!"
		wait(tweenTime + 1)
		Gui.Enabled = false
		break
	end
end



Text.Text = "Loaded!"

wait(2)

Gui.Enabled = false

print("All assets loaded.")

Screenshot_27

1 Like

Works like a charm. Thank you!

1 Like