Hello, i have a textlabel that i want to display text and it continuously cycles through a list of sentences for my loading screen. It prints it out in the output but doesn’t change the text.
local text = game.StarterGui.LoadingScreen.Frame.Textframe.Text
local LoadAssests = {
"Loading Assets...";
"Loading Terrain...";
"Loading Game Data...";
"Loading Characters...";
"Loading User Interface...";
}
while true do
for i,v in ipairs(LoadAssests) do
wait(4)
text = v
print(v)
end
end
If I’m not mistaken, if is supposed to be a loading screen for the client, you should reference PlayerGui rather than StarterGui.
I believe your code works, but your changing the StarterGui, not the playerGui.
local player = game:GetService("Players").LocalPlayer
local Textframe = player.PlayerGui:WaitForChild("LoadingScreen").Frame.Textframe
local LoadAssests = {
"Loading Assets...";
"Loading Terrain...";
"Loading Game Data...";
"Loading Characters...";
"Loading User Interface...";
}
while true do
for i,v in ipairs(LoadAssests) do
wait(4)
Textframe.Text = v
print(v)
end
end
The above code should work and I’ll even test it myself.
Also make sure this is in a local script as you can’t reference local player from the server.
If you are doing it to the client only, you have to reference PlayerGui like what @Syntheix said, because inside the local player the startergui will be stored inside the PlayerGui inside the local player.
Would it not have to be: local Textframe = player.PlayerGui:WaitForChild("LoadingScreen").Frame.Textframe
Because even while inside the PlayerGui, you still have to access the ScreenGui (LoadingScreen) which the “Frame” object is a descendant of.
Right, but in the OP he had game.StarterGui.LoadingScreen.Frame so the LoadingScreen would have to be a direct descendant of PlayerGui (assuming the path to the ScreenGui is correct originally).
The simplest solution to me is to simply make this script a local script and place it within the GUI itself. Here’s the changes that would need to be made.
--This should be a local script.
--Make this a child of LoadingScreen.
local text = script.Parent.Frame.Textframe.Text
local LoadAssests = {
"Loading Assets...";
"Loading Terrain...";
"Loading Game Data...";
"Loading Characters...";
"Loading User Interface...";
}
while true do
for i,v in ipairs(LoadAssests) do
wait(4)
text = v
print(v) --Please note, this now prints to the client and not the server, however, this probably won't affect anything.
end
end
You would actually be best having it in a Local Script inside the LoadingScreen gui because you only want that player to see it anyways. That way you could end up just deleting the GUI or the script afterwards (or whatever the OP wants to do) and you aren’t constantly running the while true do loop in the background on the server nonetheless.