Repeat wait() loops and changing text transparency

I am using a repeat wait() loop until the text transparency of a text label is set to 0, right now the loop keeps going and doesn’t stop.

Here is my code:

repeat wait()
	gui.Frame.TextLabel.TextTransparency = gui.Frame.TextLabel.TextTransparency - 0.05
	wait(0.01)
until gui.Frame.TextLabel.TextTransparency == 0.05

Thanks,

1 Like

Well, you are pretty much telling it to repeat until the Text’s Transparency is 0.05, is it reaching its goal?

Yep, it reaches it’s goal but continues the loop. It endlessly repeats itself.

It’s would be better to do that :

local TextLabel = gui.Frame.TextLabel
While wait(0.01) do
    if TextLabel.TextTransparency > 0.05 then
        TextLabel.TextTransparency -= 0.05
    end
end
2 Likes

This works, but it doesn’t execute the rest of my script.

1 Like

Can you send me the script please ?

while wait(0.01) do
	if TextLabel.TextTransparency > 0.05 then
		TextLabel.TextTransparency -= 0.05
	end
end
print("Done")

There is more before and after that but it isn’t relevant. It doesn’t print “done”.

1 Like

Ok, it’s very simple, it’s an infinite loop so it won’t read anything that under the script so you should do :

while wait(0.01) do
	if TextLabel.TextTransparency > 0.05 then
		TextLabel.TextTransparency -= 0.05
    else
        print("Done")
	end
end
1 Like

So would I have to write the rest of my script inside that loop?

1 Like

No, send your script I will see how I can help you !

script.Parent:RemoveDefaultLoadingScreen()

local event = game.ReplicatedStorage:WaitForChild("Loading")
local otherevent = game.ReplicatedStorage:WaitForChild("Loading2")
local client = game.Players.LocalPlayer.PlayerScripts:WaitForChild("LoadingScript")
local Camera = workspace.CurrentCamera
local cams = script.Cameras
local gui =  script.ScreenGui
local plr = game.Players.LocalPlayer


local number = 0

cams.Parent = game.Workspace
number = 20
event:Fire(number)
wait(2)
repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = cams.One.CFrame
gui.Parent = plr.PlayerGui
local TextLabel = gui.Frame.TextLabel
while wait(0.01) do
	if TextLabel.TextTransparency > 0.05 then
		TextLabel.TextTransparency -= 0.05
	else
		print("Done")
	end
end
repeat wait()
	repeat wait()
		gui.Frame.TextLabel.TextTransparency = gui.Frame.TextLabel.TextTransparency + 0.05
		wait(0.01)
	until gui.Frame.TextLabel.TextTransparency == 1
	wait(2)
	repeat wait()
		gui.Frame.TextLabel.TextTransparency = gui.Frame.TextLabel.TextTransparency - 0.05
		wait(0.01)
	until gui.Frame.TextLabel.TextTransparency == 0.05
	wait(2)
until game:IsLoaded()
gui:Destroy()
script:Destroy()

I’m making a loading screen, the events are for making the screen blur (it is sent to another local script inside the player scripts.)

1 Like

Couldnt you just use TweenService for this?

1 Like

You can try that :

script.Parent:RemoveDefaultLoadingScreen()

local event = game.ReplicatedStorage:WaitForChild("Loading")
local otherevent = game.ReplicatedStorage:WaitForChild("Loading2")
local client = game.Players.LocalPlayer.PlayerScripts:WaitForChild("LoadingScript")
local Camera = workspace.CurrentCamera
local cams = script.Cameras
local gui =  script.ScreenGui
local plr = game.Players.LocalPlayer


local number = 0

cams.Parent = game.Workspace
number = 20
event:Fire(number)
wait(2)
repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = cams.One.CFrame
gui.Parent = plr.PlayerGui
local TextLabel = gui.Frame.TextLabel
for v = 1, 9 do
	TextLabel.TextTransparency -= 0.05
end
print("done")
repeat wait()
	repeat wait()
		gui.Frame.TextLabel.TextTransparency = gui.Frame.TextLabel.TextTransparency + 0.05
		wait(0.01)
	until gui.Frame.TextLabel.TextTransparency == 1
	wait(2)
	repeat wait()
		gui.Frame.TextLabel.TextTransparency = gui.Frame.TextLabel.TextTransparency - 0.05
		wait(0.01)
	until gui.Frame.TextLabel.TextTransparency == 0.05
	wait(2)
until game:IsLoaded()
gui:Destroy()
script:Destroy()
1 Like

Here’s your answer. Decimals round weirdly and they won’t ever exactly equal 0.05. Use an inequality operator such as until gui.Frame.TextLabel.TextTransparency <= 0.05

If you’ve got a condition that’s supposed to end the loop, put it in the condition section of the loop and it will fix all the other problems you guys have been having down the thread.

while TextLabel.TextTransparency > 0.05 do
5 Likes

Your right but don’t forget to put a wait() int the while do !

This worked, thanks for all the help though @FireStrykerAzul !

1 Like

I know this post had been solved but i would like to suggest using TweenService for this case

local TextLabel = gui.Frame.TextLabel

local TweenService = game:GetService("TweenService")

local TweeningInfo = TweenInfo.new(0.5) -- How much time the tween should be

local goal = {}

goal.TextTransparency = 0.05

local Tween = TweenService:Create(TextLabel,TweeningInfo,goal)

Tween:Play()
2 Likes

oh my lord. TWEEN SERVICE IS LITERALLY MADE FOR THIS. it really makes me mad when people do weird bypasses instead of using the built in method.

TweenService didn’t always exist and in most scenarios outside of Roblox it doesn’t. Loops are made for this and I’d argue it’s simpler and less overhead to just make a loop. It’s certainly not a weird bypass. It’s just how programming works.

lua has the built in service. that’s what i was talking about. they’re coding in lua anyways so it’s still considered a weird bypas.