My intro script repeats itself, is there any way to cap the load?

I have this script that when the load of the Content is 0, so its fully loaded, my intro plays, but for some reason it repeats because it hit 0 again, any way to fix this? Heres my script.

–// Client

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local Camera = game.Workspace.CurrentCamera

game.Lighting.Blur.Size = 15

–// GUIs

local PlayButton = script.Parent.PLAY

–// Main

repeat wait()

Camera.CameraType = Enum.CameraType.Scriptable

until Camera.CameraType == Enum.CameraType.Scriptable

Camera.CameraType = Enum.CameraType.Scriptable

local StarterGui = game:GetService(“StarterGui”)

StarterGui:SetCore(“TopbarEnabled”,false)

repeat wait() until script.Parent.Parent == game.Players.LocalPlayer:WaitForChild(“PlayerGui”)

while wait() do

local Load = game:GetService(“ContentProvider”).RequestQueueSize

print(‘Loading game (’…Load…’)’)

if Load == 0 then

wait(3)

print(“Game Loaded”)

script.Soundsx:Play()

script.Parent.Seralee.ImageTransparency = 0

game:GetService(“RunService”).RenderStepped:connect(function()

workspace.Camera.FieldOfView = 70 + script.Soundsx.PlaybackLoudness * 0.01

game.Lighting.Blur.Size = script.Soundsx.PlaybackLoudness * 0.0185

end)

wait (21.8)

script.Parent.PLAY.Active = true

script.Parent.PLAY.Visible = true

script.Parent.Seralee.ImageTransparency = 1

script.Parent.ImageLabel.ImageTransparency = 0.9

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.8

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.7

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.6

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.5

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.4

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.3

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.2

wait ()

script.Parent.ImageLabel.ImageTransparency = 0.1

wait ()

script.Parent.ImageLabel.ImageTransparency = 0

PlayButton.MouseButton1Click:Connect(function()

Camera.CameraType = Enum.CameraType.Custom

script.Parent.ImageLabel.ImageTransparency = 1

script.Parent.ImageLabel.Visible = false

script.Parent.ImageLabel.Active = false

game.Lighting.Blur.Size = 15

wait ()

game.Lighting.Blur.Size = 12

wait ()

game.Lighting.Blur.Size = 9

wait ()

game.Lighting.Blur.Size = 6

wait ()

game.Lighting.Blur.Size = 5.5

wait ()

game.Lighting.Blur.Size = 5

script.Soundsx:Stop()

PlayButton:Destroy()

end)

end

end

Please refer to using a for loop instead of manually changing the transparency. Even better, use tween service to tween the transparency. Also, RequestQueueSize is not recommended to determine if assets are loaded. Instead, use PreloadAsync to preload your assets, and once completed perform the intro. To fix your problem where it’s running multiple times, I’d create a debounce and set it to true when the assets are loaded.

1 Like

Whats the point of using a repeat loop for something like this? It seems like it would only yield without any purpose.

The camera briefly changes, so you must wait until it changes, then change it to the desired camera type or else it will be overridden.

Also, you should be formatting your script so that it uses the ` marks:

Input:
```
--code here
```

Output:

--code here

Anyway, here is a formatted version of your script for now:

--// Client

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
game.Lighting.Blur.Size = 15

--// GUIs

local PlayButton = script.Parent.PLAY

--// Main

repeat 
	wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CameraType = Enum.CameraType.Scriptable

local StarterGui = game:GetService(“StarterGui”)
StarterGui:SetCore(“TopbarEnabled”,false)

repeat wait() until script.Parent.Parent == game.Players.LocalPlayer:WaitForChild(“PlayerGui”)

while wait() do
	local Load = game:GetService(“ContentProvider”).RequestQueueSize
	print(‘Loading game (’…Load…’)’)
	if Load == 0 then
		wait(3)
		print(“Game Loaded”)
		script.Soundsx:Play()
		script.Parent.Seralee.ImageTransparency = 0
		game:GetService(“RunService”).RenderStepped:connect(function()
			workspace.Camera.FieldOfView = 70 + script.Soundsx.PlaybackLoudness * 0.01
			game.Lighting.Blur.Size = script.Soundsx.PlaybackLoudness * 0.0185
		end)

		wait (21.8)

		script.Parent.PLAY.Active = true
		script.Parent.PLAY.Visible = true
		script.Parent.Seralee.ImageTransparency = 1
		script.Parent.ImageLabel.ImageTransparency = 0.9
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.8
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.7
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.6
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.5
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.4
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.3
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.2
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0.1
		wait ()
		script.Parent.ImageLabel.ImageTransparency = 0

		PlayButton.MouseButton1Click:Connect(function()
			Camera.CameraType = Enum.CameraType.Custom
			script.Parent.ImageLabel.ImageTransparency = 1
			script.Parent.ImageLabel.Visible = false
			script.Parent.ImageLabel.Active = false
			game.Lighting.Blur.Size = 15
			wait ()
			game.Lighting.Blur.Size = 12
			wait ()
			game.Lighting.Blur.Size = 9
			wait ()
			game.Lighting.Blur.Size = 6
			wait ()
			game.Lighting.Blur.Size = 5.5
			wait ()
			game.Lighting.Blur.Size = 5
			script.Soundsx:Stop()
			PlayButton:Destroy()
		end)
	end
end
1 Like

If you have to set it back repeatedly, you should use a while loop, because a repeat loop will always run at least once.
Basically, if you don’t need to yield and set it back again, it will still yield.

 repeat wait() until condition

or
while not condition do wait() end

The intro script repeats itself because for whatever reason, there are several unnecessary loops in your code. Especially the while wait (ew) one. It’s a non-terminating loop, it’ll always run itself again if RequestQueueSize is 0.

This is why I always say “use the condition of a while loop properly”. The exact problem here is incorrect usage of the conditional statement of the while loop.

-- No
while wait() do
    requestqueuesize
    if 0
        code
    end
end

-- Yes
requestqueuesize

while not requestqueuesize is 0
    wait
end

code after load -- OR SIMILAR

So, some optimizations:

  1. You are wrapping your entire intro into a while wait() do loop, which should be fixed, thanks @colbert2677:
while game:GetService("ContentProvider").RequestQueueSize > 0 do
	wait ()
end
-- print("Game Loaded")
  1. Wrapping all script.Parent.ImageLabel.ImageTransparency assignments in a numeric for loop will simplify things:
for i = 1, 0, -0.1 do
	script.Parent.ImageLabel.ImageTransparency = i
	wait ()
end
  1. You should probably disconnect game:GetService("RunService").RenderStepped once the play button is pressed:
local runConnection = game:GetService("RunService").RenderStepped:connect(function()
	-- ...
end)

-- code in between

PlayButton.MouseButton1Click:Connect(function()
	runConnection:Disconnect()
	
	-- ...
end)
  1. You can place game.Lighting.Blur.Size in a for loop too, although it’s more complicated:
-- ...
for i = 15, 5, -3 do
	game.Lighting.Blur.Size = i
	wait ()
end

-- the for loop stops at 6, so we have to manually assign to 5
game.Lighting.Blur.Size = 5
-- ...
  1. You can make your code more understandable by defining variables that encapsulate services and parent objects:
--As an example

local RunService = game:GetService("RunService")

local GUI = script.Parent

-- ...

RunService.RenderStepped:Connect(function() end)

GUI.ImageLabel.Seralee.ImageTransparency = 1