Improvements to my game intro

Hello there! I just started learning how create an intro for my game, and produced my first working one. I’m worried that I might be doing some bad practices on my first go, so are there any improvements that can be made?

Here’s the script (it’s a LocalScript):

game:GetService("ReplicatedFirst"):RemoveDefaultLoadingScreen()

local starterGui = game:GetService("StarterGui")
local tweenService = game:GetService("TweenService")
local players = game:GetService("Players")

local playerGui = players.LocalPlayer:WaitForChild("PlayerGui")
local gui = script.IntroGui:Clone()

local frame = gui.Frame
local title = frame.Title
local subtitle = frame.Subtitle
local gameCard = frame.Game

gui.Parent = playerGui

local info1, info2 = TweenInfo.new(3), TweenInfo.new(1)
local visible, invisible = {TextTransparency = 0}, {TextTransparency = 1}

-----------------

local function tween(item, info, obj, get)
	local myTween = tweenService:Create(item, info, obj)
	myTween:Play()

	if get then
		return myTween
	end
end

local function doTweens()
	tween(title, info1, visible)
	wait(1)
	tween(subtitle, info1, visible)
	wait(5)

	tween(title, info2, invisible)
	tween(subtitle, info2, invisible)
	wait(1)

	tween(gameCard, info2, visible)
end

local songs = {"rbxassetid://1840426770", "rbxassetid://1840426801"}

local function doTracks(num)
	wait()
	
	if num <= #songs then
		script.Ambience.SoundId = songs[num]
		script.Ambience:Play()
		script.Ambience.Ended:Wait()
		
		return doTracks(num + 1)
	end
	
	return doTracks(1)
end

-----------------

repeat wait() until starterGui:GetCore("ChatWindowSize")
starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
starterGui:SetCore("ResetButtonCallback", false)

wait(4)
script.Intro:Play()

doTweens()

-----------------

script.Intro.Ended:Wait()

if not game:IsLoaded() then
	game.Loaded:Wait()
end

tween(frame, info2, {BackgroundTransparency = 1})
local listener = tween(gameCard, info2, invisible, true)

listener.Completed:Wait()
gui:Destroy()

starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
starterGui:SetCore("ChatWindowPosition", UDim2.fromScale(0, 1 - starterGui:GetCore("ChatWindowSize").Y.Scale))

doTracks(1)

From my standpoint, there are no bad practices! Although for local starterGui, I recommend using “local StarterGui = game:WaitForChild(“StarterGui”)”, to assure it will wait till StarterGui is completely ready! (:

1 Like

you should use task.wait() instead of wait()

1 Like

You can remove this:

if not game:IsLoaded() then
	game.Loaded:Wait()
end

and change it out for this:

game.Loaded:Wait()

1 Like

Thank you, I’ll take that into consideration. As for @D0RYU, I’ll be sure to start using task.wait() now.