Why doesnt the text appear, in the script?

Hello developers,

My code has a serious reliability issue, on a rare occasion it might display the text (change the property of TextTransparency to 0). However for the image labels it has no issue, if anyone can find out the reason for this in the code below please do let me know what needs to be changed!

local Account = script.Parent.Account
local AdminPage = false

local function AccountCome()
	for i, v in pairs(Account:GetDescendants()) do
		if v.ClassName == "TextLabel" or v.ClassName == "TextButton" or v.ClassName == "TextBox" then
			v.TextTransparency = math.max(0, v.TextTransparency - 0.2)
		elseif v.ClassName == "ImageLabel" or v.ClassName == "ImageButton" then
			v.ImageTransparency = math.max(0, v.ImageTransparency - 0.2)
		end
	end
end


NavAccount.MouseButton1Click:Connect(function()
	NavAccount:TweenPosition(UDim2.new(0.779, 0,-0.162, 0))
	NavBox:TweenSizeAndPosition(UDim2.new(0.25,0,0.468,0), UDim2.new(0.725,0,0.065,0))
	Account.Visible = true
	for i = 1,5 do
		wait()
		AccountCome()

	end

end)

I have also had reliability issues with using the or statement inside an if statement.

I think these kind of lines are the problem:

if v.ClassName == "TextLabel" or v.ClassName == "TextButton" or v.ClassName == "TextBox" then

elseif v.ClassName == "ImageLabel" or v.ClassName == "ImageButton" then

It never works reliably for me either.

Unless someone else knows better, maybe just change it to something like:

local checkAccount
if v.ClassName == "TextLabel"  then checkAccount = true
if v.ClassName == "TextButton"  then checkAccount = true
if v.ClassName == "TextBox" then  then checkAccount = true
if checkAccount == true then
checkAccount = false

Use IsA, it’s just better in every way. This may help.

1 Like

If the initial transparency is 0, then decreasing 0 by 0.2 v.TextTransparency = math.max(0, v.TextTransparency - 0.2) will result in -0.2, so math.max() will choose 0, because 0 is the largest number. If you don’t change the opacity above 0.2, the text will always be opaque, which is probably the problem.

I’ve ensured that all of these solutions are in play, however there is still reliability issues but ONLY with the instances with text.

Try changing v.TextTransparency = to a specific number without using the math.

As in:

v.TextTransparency = 0.5

If the change works as expected then the math is the problem.

Otherwise it is something else.

Is there a chance the descendants haven’t loaded when the function is run?
Also wouldn’t it be better to use ‘ipairs’? I can see ‘i’ is never used, but you could try adding a checksum to ensure everything is there.