Loading screen text not updating

I want the game I’m working on to have a loading screen when a player joins so that stuff like the lighting works properly. I currently have a TextLabel inside of a ScreenGui in StarterGui which is meant to be the loading screen.

However, when I try and run the game, the text in the TextLabel says “Loading” and never updates. I have print() statements included in the for loop to see if the code outputs anything, and it outputs exactly what I want, but the actual text that I want to update doesn’t change.

As for trying to solve this problem, I’ve googled the problem and attempted to look for solutions from here on the Developer Forum, to Stack Overflow. Unfortunately this is still not working. I’ve included the code for the loading screen down below, which is a local script that is a child of the TextLabel.

local loadingGui = game.StarterGui.StartingLoad:WaitForChild("TextLabel")
local loadingText = "Loading"

local function loadingScreen()
	for i = 1, 4, 1 do
		loadingGui.Text = loadingText
		print(loadingGui.Text)
		wait(0.5)
		loadingGui.Text = loadingText .. "."
		print(loadingGui.Text)
		wait(0.5)
		loadingGui.Text = loadingText .. ".."
		print(loadingGui.Text)
		wait(0.5)
		loadingGui.Text = loadingText .. "..."
		print(loadingGui.Text)
		wait(0.5)
	end
    -- Below this for loop will be code responsible for fading the loading screen so the player can play the game.
end

loadingScreen()

This should achieve what you’re looking for:

local Players = game:GetService("Players")

local loadingText = "Loading"
local loopDuration = 4 * 4 -- How many times the for loop will run (Needs to be multiplied by 1 + the amount of dots!)

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local startingLoad = playerGui:WaitForChild("StartingLoad")
local loadingGui = startingLoad:WaitForChild("TextLabel")


local function loadingScreen()
	for i = 0, loopDuration do -- Loop needs to start at 0 now
		loadingGui.Text = loadingText..string.rep('.', i % 4) -- Using "i % 4" will max out at three dots
		print(loadingGui.Text)
		task.wait(0.5) -- It's better to use task.wait rather than wait
	end


end

loadingScreen()

replace this with

local loadingGui = game.Players.LocalPlayer.PlayerGui.StartingLoad:WaitForChild(“TextLabel”)

1 Like

Good catch! I didn’t notice that they were editing the GUI that’s in StarterGui. I’ve edited my code to reflect this :slight_smile::+1:

Thanks! This fixed the issue for me!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.