How to enable and disable gui?

  1. What do you want to achieve? make the loading gui come first, then once that is done, the intro gui is enabled

  2. What is the issue? when i try to use this

local contentProvider = game:GetService("ContentProvider")
local replicatedFirst = game:GetService("ReplicatedFirst")

local gui = script.Parent
local loadingBar = gui.LoadingBar.Inner
local percentageLabel = gui.PercentLabel


local preloadableClassnames = {
	Decal = true,
	Sound = true,
	Animation = true,
	ParticleEmitter = true,
	Beam = true,
	Trail = true,
	Texture = true,
	ImageLabel = true,
	ImageButton = true,
	MeshPart = true,
	SpecialMesh = true,
	SurfaceApperance = true,
	Shirt = true,
	Pants = true,
	Blur = true,
	ColorCorrection = true,
	DepthOfField = true,
	SunRays = true,
	Lighting = true
}

local toPreload = {}

local count = 0 -- Counts how much assets have been loaded
local loaded = false -- Boolean that says if we finished loading

local workspaceContent = workspace:GetDescendants()
local replicatedFirstContent = replicatedFirst:GetDescendants()

local Player = game.Players.LocalPlayer 
local PlayerGui = Player.PlayerGui 
local lobby = PlayerGui.lobbygui 


table.move(replicatedFirstContent, 1, #replicatedFirstContent, #workspaceContent + 1, workspaceContent) -- Combines content of Workspace and ReplicatedFirst into single table

replicatedFirst:RemoveDefaultLoadingScreen()

for i, v in workspaceContent do -- Loop threw combined content
	if typeof(v) == "Instance" and preloadableClassnames[v.ClassName] then -- Check thats content is preloadable
		table.insert(toPreload, v) -- Insert content into final table
	end
end

local function preloadAsset(asset: Instance)
	contentProvider:PreloadAsync({asset})
	count += 1
	
	local ratio = count	 / #toPreload
	loadingBar.Size = UDim2.fromScale(ratio, 1)

	percentageLabel.Text = math.floor(ratio * 100) .. "%"
end

local function Preload()
	for i, v in toPreload do
		task.spawn(preloadAsset, v)
	end
	
	while count < #toPreload or not game:IsLoaded() do
		task.wait()
	end
	
	loaded = true
	gui.Enabled = false
	lobby.Enabled = true

end

gui.Enabled = true
lobby.Enabled = false

task.spawn(Preload)

it doesnt work. specifically, the loading screen doesnt work with

local Player = game.Players.LocalPlayer 
local PlayerGui = Player.PlayerGui 
local lobby = PlayerGui.lobbygui 
--
lobby.Enabled = true 
--
lobby.Enabled = false 

without that it worked perfectly fine

  1. What solutions have you tried so far? i tried looking around on devforum but it seems this is a very specific issue. . .

without enabling
robloxapp-20240417-1813352.wmv (137.8 KB)

with enabling
robloxapp-20240417-1815209.wmv (403.5 KB)

(sorry you have to download those)

im not a scripter if you cant tell, sorry if this was really obvious

It seems like the issue is with the lobby.Enabled = true and lobby.Enabled = false lines of code. One solution you can try is to delay enabling the lobby GUI until after the loading has finished. You can do this by adding a delay before enabling the lobby GUI.

Here’s how you can modify the Preload function to include a delay before enabling the lobby GUI:

local function Preload()
    for i, v in toPreload do
        task.spawn(preloadAsset, v)
    end

    while count < #toPreload or not game:IsLoaded() do
        task.wait()
    end

    loaded = true
    gui.Enabled = false
    
    task.wait(1) -- Add a delay of 1 second before enabling the lobby GUI
    lobby.Enabled = true
end

By adding this delay, it should give the loading GUI enough time to complete before enabling the lobby GUI. Hopefully, this solution helps resolve the issue you’re facing.

(idk for sure if this works or not…)

2 Likes

that didnt seem to work, the loading screen still does not appear, but thank you for trying

Without enabling looks great. Other than that white flash when it starts.
Maybe this will help that… Just drop it in the StarterGui. (removed)
This is set up to only happen one time when you start the game.

1 Like

I found a solution, i just used a simpler loading screen with this

local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Background = script.Parent:WaitForChild("Background")

ReplicatedFirst:RemoveDefaultLoadingScreen()
local assets = game.Workspace:GetDescendants()
script.Parent.Enabled = true

for i = 1, #assets do
	local asset = assets[i]
	local percentage = math.round(i / #assets * 100)
	ContentProvider:PreloadAsync({asset})
	Background:WaitForChild("DisplayPercentage").Text = percentage.."%"
	Background:WaitForChild("AssetsLoaded").Text = "Loading Assets: "..i.."/"..#assets
	TweenService:Create(Background.BarBackground.Bar, TweenInfo.new(0.2,Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percentage/100, 1)}):Play()
	if i % 50 == 0 then
		task.wait()
	end
end
Background:WaitForChild("AssetsLoaded").Text = "Game loaded!"
wait(3)
for i, v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("Frame") then
		TweenService:Create(v, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
	elseif v:IsA("TextLabel") then
		TweenService:Create(v, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
	end
end
wait(1)
script.Parent.Enabled = false

i have no idea why that worked but oh well
it even loads better and faster

1 Like

Well I’m taking back my epic FadeIn script then.

2 Likes