Feedback on my loading screen script

I’m just beginning to script and made my first loading screen ever. How can I improve it and make it better? Also, is there a way to use an already existing Gui to make the loading screen instead of using Instance.new()?

local Players = game:GetService("Players")

local ReplicatedFirst = game:GetService("ReplicatedFirst")

local StarterGui = game:GetService("StarterGui")

local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer

local playerGui = player:WaitForChild("PlayerGui")

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

local LoadingScreenGui = Instance.new("ScreenGui")

LoadingScreenGui.IgnoreGuiInset = true

LoadingScreenGui.Parent = playerGui

LoadingScreenGui.ResetOnSpawn = false

local LoadingFrame = Instance.new("Frame")

LoadingFrame.AnchorPoint = Vector2.new(0.5, 0.5)

LoadingFrame.BackgroundColor3 = Color3.fromRGB(46, 46, 46)

LoadingFrame.BackgroundTransparency = 0

LoadingFrame.BorderSizePixel = 0

LoadingFrame.Name = "LoadingFrame"

LoadingFrame.Position = UDim2.new(0.5, 0, 0.5, 0)

LoadingFrame.Size = UDim2.new(1, 0, 1, 0)

LoadingFrame.Parent = LoadingScreenGui

local Icon = Instance.new("ImageLabel")

Icon.AnchorPoint = Vector2.new(0.5, 0.5)

Icon.BackgroundColor3 = Color3.fromRGB(46, 46, 46)

Icon.BackgroundTransparency = 1

Icon.BorderSizePixel = 0

Icon.Name = "Icon"

Icon.Position = UDim2.new(0.5, 0, 0.5, 0)

Icon.Size = UDim2.new(0.4, 0, 0.4, 0)

Icon.Parent = LoadingFrame

Icon.Image = "rbxassetid://8130616048"

Icon.ScaleType = Enum.ScaleType.Fit

local LoadingRing = Instance.new("ImageLabel")

LoadingRing.AnchorPoint = Vector2.new(0.5, 0.5)

LoadingRing.BackgroundColor3 = Color3.fromRGB(46, 46, 46)

LoadingRing.BackgroundTransparency = 1

LoadingRing.BorderSizePixel = 0

LoadingRing.Name = "LoadingRing"

LoadingRing.Position = UDim2.new(0.5, 0, 0.8, 0)

LoadingRing.Size = UDim2.new(0.035, 0, 0.035, 0)

LoadingRing.Parent = LoadingFrame

LoadingRing.Image = "rbxassetid://8130781497"

LoadingRing.ScaleType = Enum.ScaleType.Fit

local LoadingText = Instance.new("TextLabel")

LoadingText.AnchorPoint = Vector2.new(0.5, 0.5)

LoadingText.BackgroundColor3 = Color3.fromRGB(46, 46, 46)

LoadingText.BackgroundTransparency = 1

LoadingText.BorderSizePixel = 0

LoadingText.Name = "LoadingRing"

LoadingText.Position = UDim2.new(0.5, 0, 0.75, 0)

LoadingText.Size = UDim2.new(0.1, 0, 0.05, 0)

LoadingText.Parent = LoadingFrame

LoadingText.Font = Enum.Font.Oswald

LoadingText.Text = "Initiating Loader..."

LoadingText.TextColor3 = Color3.fromRGB(255, 255, 255)

LoadingText.TextScaled = true

LoadingText.TextStrokeTransparency = 1

local UIPadding = Instance.new("UIPadding")

UIPadding.PaddingBottom = UDim.new(0.1, 0)

UIPadding.PaddingLeft = UDim.new(0.1, 0)

UIPadding.PaddingRight = UDim.new(0.1, 0)

UIPadding.PaddingTop = UDim.new(0.1, 0)

UIPadding.Parent = LoadingText

-- Remove the default loading screen

ReplicatedFirst:RemoveDefaultLoadingScreen()

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut, -1)

local tween = TweenService:Create(LoadingRing, tweenInfo, {Rotation = 360})

tween:Play()

wait(3) -- Force screen to appear for a minimum number of seconds

LoadingText.Text = "Loading Core..."

if not game:IsLoaded(1) then

game.Loaded:Wait()

end

LoadingText.Text = "Loading Scripts..."

wait(1)

LoadingText.Text = "Finished"

wait(3)

LoadingFrame:TweenPosition(UDim2.new(0.5, 0, -1.25, 0),

Enum.EasingDirection.In,

Enum.EasingStyle.Linear,

0.75)

wait(1)

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)

LoadingScreenGui:Destroy()

This is my first time scripting a loading screen so be nice… or not.

If you don’t want to create a GUI via script you can simply place a ScreenGui inside of ‘ReplicatedFirst’ then parent it to PlayerGui in a local script. This allows the UI to load first.

2 Likes

Does the script work the way its supposed to?

Following up with the post I just made, I tested it in Studio and it didn’t work. I found an error in your code.

You didn’t define “Players” thus making the code fail.

Put the following line before the “player” variable:

local Players = game:GetService("Players")

1 Like

Replace the line that declares “local player” with local player = game.Players.LocalPlayer

I pasted the code in wrong and on the script it was defined. That’s my fault.

1 Like

Lots of writing here!!

I personally think you should put your GUI inside of a local script then have the local script clone the GUI into a player’s gui, as an example here

  • Local Script with IntroGui inside of it
script:WaitForChild("IntroGui"):Clone().Parent = game.StarterGui
script:Destroy() --because you wont be needing this again

compress those lines holy, I get its easier to read but MLA Format on your syntax is a little much :flushed:

For some reason when I paste it from studio it puts in line breaks. ¯_ (ツ)_/¯

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

local LoadingScreenGui = Instance.new("ScreenGui")
LoadingScreenGui.IgnoreGuiInset = true
LoadingScreenGui.Parent = playerGui
LoadingScreenGui.ResetOnSpawn = false

local LoadingFrame = Instance.new("Frame")
LoadingFrame.AnchorPoint = Vector2.new(0.5, 0.5)
LoadingFrame.BackgroundColor3 = Color3.fromRGB(46, 46, 46)
LoadingFrame.BackgroundTransparency = 0
LoadingFrame.BorderSizePixel = 0
LoadingFrame.Name = "LoadingFrame"
LoadingFrame.Position = UDim2.new(0.5, 0, 0.5, 0)
LoadingFrame.Size = UDim2.new(1, 0, 1, 0)
LoadingFrame.Parent = LoadingScreenGui

local Icon = Instance.new("ImageLabel")
Icon.AnchorPoint = Vector2.new(0.5, 0.5)
Icon.BackgroundColor3 = Color3.fromRGB(46, 46, 46)
Icon.BackgroundTransparency = 1
Icon.BorderSizePixel = 0
Icon.Name = "Icon"
Icon.Position = UDim2.new(0.5, 0, 0.5, 0)
Icon.Size = UDim2.new(0.4, 0, 0.4, 0)
Icon.Parent = LoadingFrame
Icon.Image = "rbxassetid://8130616048"
Icon.ScaleType = Enum.ScaleType.Fit

local LoadingRing = Instance.new("ImageLabel")
LoadingRing.AnchorPoint = Vector2.new(0.5, 0.5)
LoadingRing.BackgroundColor3 = Color3.fromRGB(46, 46, 46)
LoadingRing.BackgroundTransparency = 1
LoadingRing.BorderSizePixel = 0
LoadingRing.Name = "LoadingRing"
LoadingRing.Position = UDim2.new(0.5, 0, 0.8, 0)
LoadingRing.Size = UDim2.new(0.035, 0, 0.035, 0)
LoadingRing.Parent = LoadingFrame
LoadingRing.Image = "rbxassetid://8130781497"
LoadingRing.ScaleType = Enum.ScaleType.Fit

local LoadingText = Instance.new("TextLabel")
LoadingText.AnchorPoint = Vector2.new(0.5, 0.5)
LoadingText.BackgroundColor3 = Color3.fromRGB(46, 46, 46)
LoadingText.BackgroundTransparency = 1
LoadingText.BorderSizePixel = 0
LoadingText.Name = "LoadingRing"
LoadingText.Position = UDim2.new(0.5, 0, 0.75, 0)
LoadingText.Size = UDim2.new(0.1, 0, 0.05, 0)
LoadingText.Parent = LoadingFrame
LoadingText.Font = Enum.Font.Oswald
LoadingText.Text = "Initiating Loader..."
LoadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
LoadingText.TextScaled = true
LoadingText.TextStrokeTransparency = 1

local UIPadding = Instance.new("UIPadding")
UIPadding.PaddingBottom = UDim.new(0.1, 0)
UIPadding.PaddingLeft = UDim.new(0.1, 0)
UIPadding.PaddingRight = UDim.new(0.1, 0)
UIPadding.PaddingTop = UDim.new(0.1, 0)
UIPadding.Parent = LoadingText
-- Remove the default loading screen

ReplicatedFirst:RemoveDefaultLoadingScreen()

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut, -1)
local tween = TweenService:Create(LoadingRing, tweenInfo, {Rotation = 360})
tween:Play()

task.wait(3) -- Force screen to appear for a minimum number of seconds
LoadingText.Text = "Loading Core..."
if not game:IsLoaded(1) then
	game.Loaded:Wait()
end
LoadingText.Text = "Loading Scripts..."
task.wait(1)
LoadingText.Text = "Finished"
task.wait(3)
LoadingFrame:TweenPosition(UDim2.new(0.5, 0, -1.25, 0),
	Enum.EasingDirection.In,
	Enum.EasingStyle.Linear,
	0.75)
task.wait(1)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
LoadingScreenGui:Destroy()

I’ve also replaced wait() with task.wait(), thank me later.

1 Like