Loading screen not working?

Hey there! I’m at the moment trying to make a loading screen using the ReplicatedFirst table. I was testing the LocalScript but realised that it isn’t working and that the Instance wasn’t in the Players PlayerGui

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.Image = "rbxassetid://9655626311"
Background.ZIndex = 20
Background.BackgroundTransparency = 1
Background.Parent = screenGui
screenGui.Parent = playerGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then
game.Loaded:Wait()
end

screenGui:Destroy()

Thanks for reading!

game:IsLoaded() is when the server is loaded. Instead, I would detect their FPS and wait for it to go up before removing the GUI.

1 Like

Why though? Is it better than detecting the server?

The client loads stuff in differently than the server, it will render the parts, unlike the server. You can also wait a fixed amount of time, like 30 seconds, or wait for a specific sound or image to load.

I already know this but the thing is the screenGui and the Background don’t even appear in the PlayerGui.

This script should be in RepicatedFirst. Has nothing to do with screenGui

1 Like

It already is though. My fault I spelt it wrong.

Understandable … Go copy this script and drop it in RepicatedFirst. Make sure it’s working … then use it to figure out why yours isn’t

1 Like

I believe your issue is that the game may have already loaded and the screengui gets destroyed before the image could load. If you want to keep the image stay for some time, add a wait() or use a for loop.

Try using this code for your script:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.Image = "rbxassetid://9655626311"
Background.ZIndex = 20
Background.BackgroundTransparency = 1
Background.Parent = screenGui
screenGui.Parent = playerGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then
	game.Loaded:Wait()
end

for i = 1,100 do
	task.wait(0.1) -- change this to how long you want the image to last (the lower it is, the longer it lasts, the higher it is, the shorter it lasts
end

screenGui:Destroy()
1 Like

Is it meant to be a blank screen?

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = playerGui

local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.BackgroundTransparency = 1
Background.Image = "rbxassetid://9655626311"
Background.Parent = screenGui

-- Remove the default loading screen
ReplicatedFirst:RemoveDefaultLoadingScreen()

wait(5)  -- Force screen to appear for a minimum number of seconds
if not game:IsLoaded() then
	game.Loaded:Wait()
end
screenGui:Destroy()

Not sure what that Background.ZIndex = 20 is meant to be

1 Like

Thanks a lot for the help! I wanna add tweenservice when 12.5 seconds have passed I don’t know how to though.

1 Like

You are welcome. Could you please explain what you want to do with tween service, I do not quite understand what you want to do.

1 Like

You want them to wait 12.5 then do a tween? They will log off.
On that same page is an example of how to add text and a tween.

1 Like

So I want this background Image to fade away when the game has finished loading. I hope that is understandable.

1 Like

The ZIndex = 20 means that it the Instance will be at layer 20 so that anything in a ZIndex lower than 20 will stay behind the ImageLabel.

Okay, that is pretty simple.
Here is your updated code:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.Image = "rbxassetid://9655626311"
Background.ZIndex = 20
Background.BackgroundTransparency = 1
Background.Parent = screenGui
screenGui.Parent = playerGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then
	game.Loaded:Wait()
end

for i = 1,100 do
	task.wait(0.1) -- change this to how long you want the image to last
	
	if i == 100 then -- if game finished loading
		local tween = TweenService:Create(Background, TweenInfo.new(1), {ImageTransparency = 1})
		tween:Play() -- plays tween
		tween.Completed:Wait()
	end
end

task.wait(1) -- to let the tween finish
screenGui:Destroy()
1 Like

you should use tween.completed and you should set reset on spawn to false

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.ResetOnSpawn = false
local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.Image = "rbxassetid://9655626311"
Background.ZIndex = 2
screenGui.DisplayOrder = 100
Background.BackgroundTransparency = 1
Background.Parent = screenGui
screenGui.Parent = playerGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then
	game.Loaded:Wait()
end

for i = 1,100 do
	task.wait(0.1) -- change this to how long you want the image to last
	
	if i == 100 then -- if game finished loading
		local tween = TweenService:Create(Background, TweenInfo.new(1), {ImageTransparency = 1})
		tween:Play()
         tween.Completed:Wait() -- to let the tween finish
	end
end
screenGui:Destroy()
2 Likes

So the background appears and everything but the ZIndex doesn’t seem to be 20 and the TweenService doesn’t play.

The tweenService seems to work here but the ZIndex still doesn’t seem to work properly

Instead of changing the ZIndex, change the ScreenGui display order. Changing the ZIndex of the image only affects any other UI element in the ScreenGui, it won’t affect other ScreenGuis, unless you change the DisplayOrder of the ScreenGui.

Updated Code:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.DisplayOrder = 20
screenGui.ResetOnSpawn = false

local Background = Instance.new("ImageLabel")
Background.Size = UDim2.new(1, 0, 1, 0)
Background.Image = "rbxassetid://9655626311"
Background.BackgroundTransparency = 1
Background.Parent = screenGui
screenGui.Parent = playerGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then
	game.Loaded:Wait()
end

for i = 1,100 do
	task.wait(0.1) -- change this to how long you want the image to last
	
	if i == 100 then -- if game finished loading
		local tween = TweenService:Create(Background, TweenInfo.new(1), {ImageTransparency = 1})
		tween:Play()
		tween.Completed:Wait()
	end
end

screenGui:Destroy()
2 Likes