Could this be made better?

This is the code:

while task.wait(0) do
	if game:IsLoaded() then
		local w = game:GetService('TweenService')
		local i = TweenInfo.new(1.5,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0)
		local goal = {['BackgroundTransparency'] = 0}
		local e = w:Create(script.Parent.Main,i,goal)
		e:Play()
		e.Completed:Connect(function()
			task.wait(0.5)
			script["Pop Sound"]:Play()
			script["Pop Sound"].Ended:Connect(function()
				for i,v in pairs(script.Parent:GetChildren()) do
					if v:IsA('Frame') then
						if v.Name ~= 'Main' then
							v.BackgroundTransparency = 1
						end
					elseif v:IsA('TextLabel') then
						v.TextTransparency = 1
					end
				end
				local a = game:GetService('TweenService')
				local q = {['BackgroundTransparency'] = 1}
				a:Create(script.Parent.Main,i,q):Play()
			end)
		end)
		break
	end
end
1 Like

I don’t really see why you need to loop this. Also, task.wait(0) is equal to task.wait(), so there really isn’t any reason to add task.wait(0) when you could just do task.wait().

Yeah, I know. Unless this script is inside of ReplicatedFirst, game:IsLoaded() is not needed.

It is also good practice to specify services first, for example, start with:

local TweenService = game:GetService("TweenService")

I also would name everything what they are called instead of certain letters, just to make people you hire’s job easier, and to make your life easier as well. You will see me change a bunch of the variables in the final script as well.

Besides the variable, the TweenInfo is ok. I would just add some spaces in between the commas to make things look cleaner.

local Info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)

I have a life hack for you. You actually don’t need a separate variable for goal. You can just do:

local Tween = TweenService:Create(script.Parent.Main, Info, {BackgroundTransparency = 0})

It makes your script more efficient.

Playing the Tween is just fine, so I am going to skip that.

RBXScriptConnect’s can start causing lag in the long term. Only do it if you can easily :Disconnect() it, or if you are using it long term.

What you can do to make your script probably 10x more efficient is doing this:

Tween.Completed:Wait()

It immediately removes the need to :Connect(function(), and saves a few lines of code.

Same thing with Sound.Ended. :Wait() may not get you everywhere, but it will work most of the time.

Now here is the finalized script:

local TweenService = game:GetService('TweenService')

local Info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)
local Tween = TweenService:Create(script.Parent.Main, Info, {BackgroundTransparency = 0})
Tween:Play()
Tween.Completed:Wait()
task.wait(0.5)
script["Pop Sound"]:Play()
script["Pop Sound"].Ended:Wait()
for _, v in pairs(script.Parent:GetChildren()) do
	if v:IsA('Frame') then
		if v.Name ~= 'Main' then
			v.BackgroundTransparency = 1
		end
	elseif v:IsA('TextLabel') then
		v.TextTransparency = 1
	end
end
TweenService:Create(script.Parent.Main,Info, {BackgroundTransparency = 1}):Play()
3 Likes