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()
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 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()
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
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()
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()
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()