I’m working on a super simple loading screen that appears when a player joins. For some reason, the UI doesn’t appear at all - I have been working on fixing this for a good 5-6 hours now and have consulted some really talented lua developers who haven’t been able to figure this out, though I feel like the solution should be really simple.
I have pasted my code and a picture of the setup in Explorer below. As I said, the UI doesn’t appear at all - I added several print commands in different parts of the code as part of my debugging efforts and none of them came through, meaning that literally nothing is happening when this script runs.
Code
local loadScreen = script.Parent
local open = script.Parent.isOpen
local text = script.Parent.infoLabel
local info = script.Parent.TextLabel
local welcome = script.Parent.Parent.welcomeFrame
local open2 = script.Parent.Parent.welcomeFrame.isOpen
local Players = game:GetService("Players");
function onCharacterAdded()
loadScreen.Visible = true
open.Value = true
wait(2)
text.Text = [[If you like this game, please consider improving the ratings!]]
wait(3)
text.Text = [[You can instantly teleport back to the spawn in the Settings tab!]]
wait(3)
text.Text = [[Gamepass purchases fund more badges and my other games!]]
wait(2)
text.Text = [[Loading finished - enjoy the game!]]
loadScreen.Visible = false
open.Value = false
welcome.Visible = true
open2.Value = true
end
Players.LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
I’ve tried just about everything I’ve been told. I’ve added prints to debug, I’ve tried this script in StarterPlayerScripts, Workspace, StarterCharacterScripts, etc. I’ve even tried stupid things like using a Script instead of a LocalScript, changing certain parts of the code that should be working, adding an unnecessary amount of variables, etc.
I feel like this should be a really simple fix but I haven’t found anybody who can figure it out, so I decided to come here.
Try removing the ; after the (“Players”). Also, when you added the print statements, did it print anything out? And are there any errors? just reread the first paragraph, and found out they didn’t run.
LocalScripts aren’t guaranteed to execute before CharacterAdded fires. You can just call the function directly below without connecting it to an event, not necessary to do that from a LocalScript unless it’s a non-resetting Gui that you’re controlling visibility for (which is also unnecessary because that behaviour can be natively achieved).
@LoveTheBears101 The semicolon has nothing to do with the script. It’s common for a lot of languages to require semicolons after every line of code: for Lua, it’s optional.
ShowDevelopmentGui does not carry over into play solo sessions nor live games. That is strictly used for determining whether Guis should be visible while in Studio mode or not. This toggle is also native via the UI Editor (click “UI” in the topbar).
You could try adding multiple breakpoints through out the code and check if there are any nil variables or variables that haven’t been assigned any value.
I also recommend adding this to ReplicatedFirst and calling the function ReplicatedFirst:RemoveDefaultLoadingScreen() after you’ve loaded the GUI. (Once the problem has been solved)*
Sometimes, CharacterAdded isn’t fired because the players character may spawn before the script is executed.
What I would recommend is putting this in replicated first, as anything in there will be loaded before anything else. Clone the screen GUI into the playerGUI , then execute the rest of the code.
This probably won’t work, but what happens if you run it, wait a few seconds, then reset your character? The OnCharacterAdded may not be running because your character loads before the script runs, so if you reset, the event should (theoretically) run.
If resetting the character makes it show up, maybe try calling the function at the bottom of the script so it initially runs, then connects the function to the event.