So in some games i’ve seen that their loading screen has a skip key in which when you press a key the loading screen bar becomes full and just goes away.
I wanna do that i know that they use ContendProvider and so do I, but i don’t know that how can i make it skip because my UIs loading bar’s size depends on the assets loaded by The ContendProvider and the loading screen only goes away when the size property Is (1,0,1,0) but if the CP doesn’t allow the bar to go full it doesn’t let me skip.
Here’s the script for the loading process (Not The Full Script Only The Part Which Starts It)
local ContendProvider = game:GetService("ContentProvider")
local thegame = game.Workspace:GetDescendants()
local stuff = #thegame
for i,v in pairs(thegame) do
LoadingScreen.MainFrame.LoadingSymbol.Text = "Loading Assets ".. i .. " /".. stuff
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(i/stuff,0,1,0)
ContendProvider:PreloadAsync({v})
end
And Here’s The Part Which Tries To Make The Part Skip.
userinputservice.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space and LoadingScreen.MainFrame.BackgroundTransparency == 0 then
print("Skipped")
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(1,0,1,0)
end
end)
You can also watch This clip of how it is Not working also make sure to look at the output cause it says how many times i pressed the spaceBar.
In the Clip you can see that when i press the spacebar the bar becomes full for half a second, i don’t want that i want the CP to stop. So It Can skip.
I usually create a value called “Loading” (Bool) and put an if statement in the loop.
If the Loading value is false, the loading will stop. And if it’s true, it will do nothing and continue loading.
What I recommend is doing the steps above, when the player hits the Space key. Then you can hide the GUI.
local ContendProvider = game:GetService("ContentProvider")
local thegame = game.Workspace:GetDescendants()
local stuff = #thegame
for i,v in pairs(thegame) do
LoadingScreen.MainFrame.LoadingSymbol.Text = "Loading Assets ".. i .. " /".. stuff
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(i/stuff,0,1,0)
ContendProvider:PreloadAsync({v})
userinputservice.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space and LoadingScreen.Enabled then
print("Skipped")
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(1,0,1,0)
LoadingScreen.Enabled = false --Assuming LoadingScreen is a ScreenGui object
break
end
end)
end
When break is inserted into a loop, the loop breaks.
local ContendProvider = game:GetService("ContentProvider")
local thegame = game.Workspace:GetDescendants()
local stuff = #thegame
local skipped = false
for i,v in pairs(thegame) do
if not skipped then
LoadingScreen.MainFrame.LoadingSymbol.Text = "Loading Assets ".. i .. " /".. stuff
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(i/stuff,0,1,0)
ContendProvider:PreloadAsync({v})
else
break
end
end
userinputservice.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space and LoadingScreen.MainFrame.BackgroundTransparency == 0 then
skipped = true
LoadingScreen.MainFrame.LoadingBar.Loading.Size = UDim2.new(1,0,1,0)
end
end)