Loading screen disappearing as soon as the game loads

So, I’ve been working on a Loading Screen for my game, and its’ been working fine for a while, but now I’m having a problem where the loading screen is instantly destroyed once the game loads, without playing the tweens.
I started having this issue right after I changed the ScreenGui’s ZIndexBehavior to Global and changed the Z index of the things inside it to increments of 100(as recommended on the Developer Hub site).
Any help would be very much appreciated!
All the code is in a LocalScript by the way.

My code:

game.ReplicatedFirst:RemoveDefaultLoadingScreen()

local PlayerGUI = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local GUI = script.LoadingScreen:Clone()
GUI.Parent = PlayerGUI

repeat
	for i = 1, 30, 1 do
		GUI.Spinner.Rotation += 5
		wait(0.03)
	end
	if GUI.Text.Text == "LOADING." then
		GUI.Text.Text = "LOADING.."
	elseif GUI.Text.Text == "LOADING.." then
		GUI.Text.Text = "LOADING..."
	elseif GUI.Text.Text == "LOADING..." then
		GUI.Text.Text = "LOADING."
	end
until game:IsLoaded() and game.Players.LocalPlayer.Character ~= nil

local tween = game:GetService("TweenService"):Create(GUI.Spinner, TweenInfo.new(1.5), {Rotation = 0})
tween:Play()
local textTween = game:GetService("TweenService"):Create(GUI.Text, TweenInfo.new(1.5), {TextTransparency = 1; TextStrokeTransparency = 1})
textTween:Play()
wait(1.85)
GUI.LeftWall:TweenPosition(UDim2.new(-2,0,0,0),"InOut","Sine",1)
GUI.RightWall:TweenPosition(UDim2.new(3,0,0,0),"InOut","Sine",1)
GUI.Spinner:TweenPosition(UDim2.new(2,0,0,0),"InOut","Sine",1)
wait(2)
GUI:Destroy()
1 Like

Isn’t that the whole point of your code???

It’s supposed to play the exiting tweens first

then destroy the GUI

Did you read the first part of the post???

Just change it to

local Number = 0
repeat
    Number = Number +1
	for i = 1, 30, 1 do
		GUI.Spinner.Rotation += 5
		wait(0.03)
	end
	if GUI.Text.Text == "LOADING." then
		GUI.Text.Text = "LOADING.."
	elseif GUI.Text.Text == "LOADING.." then
		GUI.Text.Text = "LOADING..."
	elseif GUI.Text.Text == "LOADING..." then
		GUI.Text.Text = "LOADING."
	end
until game:IsLoaded() and game.Players.LocalPlayer.Character ~= nil and Number.Value >= 5

Can’t you just add in a little wait? Like 2 seconds once everything is finished? Or use Tween.Completed?

I do have a wait between the tweens playing and the gui destroying

1 Like

How does that help? It looks like it just delays the tweens and everything after the loop until 5 seconds have passed… how would that change anything?

Okay what the heck. I had the Studio Camera above a block when I was testing before, then I moved the camera away from the block and tested it and now it works, I tried above the block again and it doesn’t then… I tried both with the ZIndex’s changed back to increments of 1.
This has to be a bug(I don’t have access to Bug Report though).(Maybe it has to do with the Block having a Script with a Touched connected Event inside it?)

Maybe you should wait a little longer, the player gui probably loaded and then you loaded when the gui was being destroyed…
that’s estimated 5-10 seconds loading, it usually takes me 10 seconds to load in a game on studio

1 Like

If the GUI is being destroyed before the tween is completed, then use the Completed event of the tween.

It’s being destroyed before the Tween even starts(as far as I can tell), and I have the Wait() wait for longer then the Tween’s time anyway.

Use the Completed event of the tween so that the GUI doesn’t get destroyed immediately.

I’m marking this as the solution so y’all don’t keep posting at something that’s been fixed(kinda)…

? I have it so that the Character is not equal to nil(meaning it is in the game and controllable) before doing anything else.
(Also your post seems a bit off-topic.)