Roblox Lua Loading Screen with Skip Button
Here's a complete script that creates a loading screen with a skip button for your Roblox game. This script will show a loading screen while assets are loading and allow players to skip the loading process if they want.
Server Script (ServerScriptService)
-- ServerScriptService/LoadingScreenHandler.server.lua
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
-- Wait for the player's character to load
player.CharacterAdded:Wait()
-- Send a remote event to the client to show the loading screen
local loadingScreen = player:FindFirstChild("LoadingScreen")
if not loadingScreen then
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "ShowLoadingScreen"
remoteEvent.Parent = player
remoteEvent:FireClient(player)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Local Script (StarterPlayerScripts)
-- StarterPlayerScripts/LoadingScreen.client.lua
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local loadingScreen = Instance.new("ScreenGui")
loadingScreen.Name = "LoadingScreen"
loadingScreen.Parent = player:WaitForChild("PlayerGui")
-- Create the loading screen frame
local frame = Instance.new("Frame")
frame.Name = "LoadingFrame"
frame.Size = UDim2.new(1, 0, 1, 0)
frame.BackgroundColor3 = Color3.fromRGB(25, 25, 25)
frame.BackgroundTransparency = 0.8
frame.BorderSizePixel = 0
frame.Parent = loadingScreen
-- Create the loading text
local loadingText = Instance.new("TextLabel")
loadingText.Name = "LoadingText"
loadingText.Size = UDim2.new(0.8, 0, 0.2, 0)
loadingText.Position = UDim2.new(0.1, 0, 0.4, 0)
loadingText.BackgroundTransparency = 1
loadingText.Text = "Loading Assets..."
loadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
loadingText.TextScaled = true
loadingText.Font = Enum.Font.GothamBold
loadingText.Parent = frame
-- Create the loading bar
local loadingBar = Instance.new("Frame")
loadingBar.Name = "LoadingBar"
loadingBar.Size = UDim2.new(0.8, 0, 0.05, 0)
loadingBar.Position = UDim2.new(0.1, 0, 0.55, 0)
loadingBar.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
loadingBar.BorderSizePixel = 0
loadingBar.Parent = frame
local loadingBarFill = Instance.new("Frame")
loadingBarFill.Name = "LoadingBarFill"
loadingBarFill.Size = UDim2.new(0, 0, 1, 0)
loadingBarFill.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
loadingBarFill.BorderSizePixel = 0
loadingBarFill.Parent = loadingBar
-- Create the skip button
local skipButton = Instance.new("TextButton")
skipButton.Name = "SkipButton"
skipButton.Size = UDim2.new(0.3, 0, 0.1, 0)
skipButton.Position = UDim2.new(0.35, 0, 0.7, 0)
skipButton.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
skipButton.TextColor3 = Color3.fromRGB(255, 255, 255)
skipButton.Text = "Skip Loading"
skipButton.TextScaled = true
skipButton.Font = Enum.Font.GothamBold
skipButton.Parent = frame
-- Function to simulate loading progress
local function simulateLoading()
local progress = 0
local loadingInterval = 0.05 -- seconds
while progress < 1 and loadingScreen.Parent ~= nil do
progress = math.min(progress + loadingInterval, 1)
loadingBarFill.Size = UDim2.new(progress, 0, 1, 0)
-- Update loading text
if progress < 0.3 then
loadingText.Text = "Loading Assets..."
elseif progress < 0.6 then
loadingText.Text = "Almost there..."
elseif progress < 0.9 then
loadingText.Text = "Finalizing..."
else
loadingText.Text = "Ready!"
end
task.wait(loadingInterval)
end
end
-- Skip button functionality
skipButton.MouseButton1Click:Connect(function()
-- Immediately complete the loading bar
loadingBarFill.Size = UDim2.new(1, 0, 1, 0)
loadingText.Text = "Loading Skipped!"
-- Hide the loading screen after a short delay
task.wait(1)
loadingScreen:Destroy()
end)
-- Start the loading simulation
simulateLoading()
-- Hide the loading screen when loading is complete
task.wait(1) -- Adjust this delay as needed
loadingScreen:Destroy()
How to Use This Script
-
Server Script:
- Create a new Script in ServerScriptService and paste the first code block.
-
Local Script:
- Create a new LocalScript in StarterPlayerScripts and paste the second code block.
Customization Options
-
Appearance:
- Change colors, sizes, and positions in the local script to match your game's theme.
- Modify the loading text messages to be more specific to your game.
-
Loading Simulation:
- The current script simulates loading progress. For a real implementation, you might want to:
- Track actual asset loading progress
- Connect to a remote event that reports loading progress from the server
-
Skip Behavior:
- Currently, the skip button just completes the loading bar. You might want to:
- Add a confirmation dialog
- Only allow skipping after a certain time
- Implement different behavior when skipping (like loading lower quality assets)
-
Animation:
- You can add tween animations to make the loading screen more visually appealing.
This script provides a complete loading screen experience with a skip button that you can customize to fit your game's needs.