(Solved) Script Won't Change Text Transparency

Expected Output:
The loading screen is supposed to fade out and destroy the clone of the loading screen from ReplicatedFirst when the game is done ‘loading’.

Output:
The background fades out, but the TextLabels don’t. The script also doesn’t destroy the LoadingScreen, so it remains in PlayerGui.

What I’ve Done:
I’ve searched all over for answers as to why this is happening, but I couldn’t find any.

Local Script (Controlling the Process:)

game.ReplicatedFirst:RemoveDefaultLoadingScreen()

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local loadingScreen = script.LoadingScreen:Clone()
loadingScreen.Parent = playerGui

local background = loadingScreen.Background
local gameName = loadingScreen.GameName
local loading = loadingScreen.Loading

wait(10)

function fadeAll()
	loading.TransparencyControl:Destroy()
	wait(0.10)
	while true do
		wait(0.010)
		background.Transparency = background.Transparency + 0.10
	end
	while true do
		wait(0.010)
		gameName.TextTransparency = gameName.Transparency + 0.10
	end
	repeat
		wait(0.010)
		loading.TextTransparency = loading.Transparency + 0.10
	until loading.TextTransparency >= 1
end

fadeAll()

wait(0.10)

loadingScreen:Destroy()

Video of the Issue:

Im confident the issue is in how you’re doing your loops. Why are you making a loop for each of the elements in your UI when they could all be in a single loop?

repeat
	wait(0.010)
	background.Transparency = background.Transparency + 0.10
	gameName.TextTransparency = gameName.Transparency + 0.10
	loading.TextTransparency = loading.Transparency + 0.10
until loading.TextTransparency >= 1

but anyways, basically the issue is that this loop is going on forever since you havent put anything to break it

I agree with this. There’s alot to go over and alot of ways on going about this but I think the values are all over the place here.

I think this is what it should look like for this?

The loop should break on the until.

repeat
	wait(0.010)
	background.Transparency += 0.10
	gameName.TextTransparency += 0.10
	loading.TextTransparency += 0.10
until loading.TextTransparency >= 1

I didn’t think about that, also I don’t know how to break loops as I don’t know a lot of things about scripting. I tested each line and it turns out every time a loop is introduced the script stops. I’m probably going to make one loop for everything so it all goes transparent before it stops.

i think i actually know why you’re getting this wrong

youre assuming that if you do loops like these

while true do
--do something
end

while true do
--do some other thing
end

that they run simultaneously, but that is not the case. the code under the first loop will not run until the loop is broken.
another form of doing what youre tryna do is

while true do
	gameName.TextTransparency += 0.10
	if gameName.TextTransparency >=1 then break end --break ends the loop
	wait(0.01)
end
loadingScreen:Destroy() --this wont run until BREAK

Yeah, that’s what I thought at first but I was wrong. Now I understand that it won’t run until you break the above loop.

another thing that you could maybe find interesting, did you know that instead of doing:

while true do
--do something
	wait(0.01) --wait some amount
end

you can instead do:

while wait(0.01) do --add wait() instead of true

--it will always wait the amount on each loop 😉
end

not a big difference but just a treat

1 Like

https://developer.roblox.com/en-us/api-reference/class/TweenService

Might be worth learning how to use the “TweenService” for this.

2 Likes