Textlabel disappeared without tweening

The TextLabel “percentageCounter” seemingly disappears immediately for no reason (as far as know).
Details:

LocalScript:

--LocalScript
function preloadAssets()
	local assetCounter = assetloadingBKGR.assetCounter
	local PercentageCounter = assetloadingBKGR.percentageCounter
	local loadingWheel = assetloadingBKGR.loadingWheelBKGR
	local assets = game.Workspace:GetDescendants()
	
	local loadingWheelTween = game.TweenService:Create(loadingWheel, TweenInfo.new(1.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, -1, false, 0.5), {Rotation = loadingWheel.Rotation + 360})
	loadingWheelTween:Play()
	
	for i, asset in ipairs(assets) do
		local percentage = math.ceil((i / #assets) * 100) / 100
		game.ContentProvider:PreloadAsync({asset})
		--assetCounter.Text = "Loading Assets: ".. i .."/" ..#assets
		PercentageCounter.Text = string.format("%.2f", percentage)
		game.TweenService:Create(Bar, TweenInfo.new(0.1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Size = UDim2.new(percentage, 0, 1, 0)}):Play()
		task.wait()
	end
	
	tweenModule.tweenTransparencyPlayFn(assetloadingBKGR, 1, 1.5, "Sine", 2)
	loadingWheelTween:Cancel()
end

ModuleScript (the tweenModule):

local module = {}

function module.tweenTransparencyPlayFn(parentInstance: Instance?, transparencyValue: number, tweenDuration: number, easingStyle: string, tweenDelay: number, includeParentInstance: boolean?, includeBKGRtransparency: boolean?, waitForTweens: boolean?)
	local array = parentInstance:GetDescendants()
	if includeParentInstance then table.insert(array, parentInstance) end
	
	for i, instance in ipairs(array) do
		local propertiesToTween = {}
		
		if pcall(function() return instance.Transparency end) then
			propertiesToTween["Transparency"] = transparencyValue
		elseif instance.Name == "percentageCounter" then
			propertiesToTween["TextTransparency"] = transparencyValue
		elseif instance:IsA("GuiLabel") or instance:IsA("TextLabel") then
			propertiesToTween["TextTransparency"] = transparencyValue
		elseif instance:IsA("Frame") and includeBKGRtransparency then
			propertiesToTween["BackgroundTransparency"] = transparencyValue
		else
			continue
		end

		--pcall(function() instance.Visible = true instance.Active = true end)
		
		local tweenInfo = TweenInfo.new(tweenDuration, Enum.EasingStyle[easingStyle], Enum.EasingDirection.In, 0, false, tweenDelay or 0)
		local tweenPlay = game.TweenService:Create(instance, tweenInfo, propertiesToTween)
		tweenPlay:Play()
		
		if i == #array and waitForTweens then
			tweenPlay.Completed:Wait()
		end
	end
end

return module

The elseif instance.Name == "percentageCounter" then was a temporary solution, now it comes back to haunt me again.

Hierarchy:
image

Probably because you never tweened it :man_shrugging:

LocalScript:

--LocalScript
function preloadAssets()
    local assetCounter = assetloadingBKGR.assetCounter
    local PercentageCounter = assetloadingBKGR.percentageCounter
    local loadingWheel = assetloadingBKGR.loadingWheelBKGR
    local assets = game.Workspace:GetDescendants()
    
    local loadingWheelTween = game.TweenService:Create(loadingWheel, TweenInfo.new(1.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, -1, false, 0.5), {Rotation = loadingWheel.Rotation + 360})
    loadingWheelTween:Play()
    
    for i, asset in ipairs(assets) do
        local percentage = math.ceil((i / #assets) * 100) / 100
        game.ContentProvider:PreloadAsync({asset})
        --assetCounter.Text = "Loading Assets: ".. i .."/" ..#assets
        PercentageCounter.Text = string.format("%.2f", percentage)
        game.TweenService:Create(Bar, TweenInfo.new(0.1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Size = UDim2.new(percentage, 0, 1, 0)}):Play()
        task.wait()
    end
    
    tweenModule.tweenTransparencyPlayFn(assetloadingBKGR, 1, 1.5, "Sine", 2, true) -- Include the parent instance in tweening
    loadingWheelTween:Cancel()
    
    -- Fade out the percentageCounter TextLabel
    game.TweenService:Create(PercentageCounter, TweenInfo.new(0.1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {TextTransparency = 1}):Play() -- Tween out the text
end

banner

game.TweenService:Create(PercentageCounter, TweenInfo.new(0.1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {TextTransparency = 0}):Play() -- tween the transparency of PercentageCounter
--i probably dont need to tween the text of the percentageCounter

could you please elaboorate? beginner here😬

Oh it’s because of this

It checks if there’s an error accessing the Transparency attr, if it doesn’t error it will run the condition if not, well-- it just wont run. And course with TextLabels using “TextTransparency” instead. You can either fix that or use my code which was just my own personal quick fix.

banner

I just would stay away from pcall, anyways here you go:

 if instance:IsA("GuiObject") and instance.Transparency ~= nil then
        propertiesToTween["Transparency"] = transparencyValue
    elseif instance:IsA("TextLabel") then
        propertiesToTween["TextTransparency"] = transparencyValue
    elseif instance:IsA("GuiLabel") then
        propertiesToTween["TextTransparency"] = transparencyValue
    elseif instance:IsA("Frame") and includeBKGRtransparency then
		propertiesToTween["BackgroundTransparency"] = transparencyValue
	else
		continue
	end

When using instance.Transparency ~= nil it gets me an exception error. Which is also my problem at my previous topic [Find property of a guiObject - @DiscoDino01].

I just have to move the pcall() down the if statements

		if instance:IsA("GuiLabel") or instance:IsA("TextLabel") then
			propertiesToTween["TextTransparency"] = transparencyValue
		elseif instance:IsA("Frame") and includeBKGRtransparency then
			propertiesToTween["BackgroundTransparency"] = transparencyValue
		elseif pcall(function() return instance.Transparency end) then
			propertiesToTween["Transparency"] = transparencyValue
		else
			continue
		end

Thanks @creepkiller1234 for pointing out the problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.