My loading screen won't fade away using Tweens

Gday lads. I’ve tried to make a loading screen that counts the assets, says “Assets Loaded.” and then the GUI transparency fades to 1 before being destroyed. However i get the “Unable to cast to Dictionary” text. If someone could provide some explanation and possible solution, I’d be eternally grateful.

Here is the script that I’ve fiddled around with (everything worked until I added the tweening stuff):

local ReplicatedFirst = game:GetService('ReplicatedFirst') 
local ContentProvider = game:GetService("ContentProvider")
-- tweening stuff
local TweenService = game:GetService("TweenService")
local UIObjects = {
	script.Parent.LoadingText,
	script.Parent.LoadingText.Textbox
}
local Tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false)
local Tween = TweenService:Create(
	UIObjects,
	TweenInfo ,
	{script.Parent.LoadingText.BackgroundTransparency == 1 , script.Parent.LoadingText.Textbox.TextTransparency == 1}
)


local Assets = game:GetDescendants() 

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
ReplicatedFirst:RemoveDefaultLoadingScreen()

repeat wait() until game:IsLoaded()
for i = 1, #Assets do
	local asset = Assets[i]

	ContentProvider:PreloadAsync({asset})
	script.Parent.LoadingText.Textbox.Text = "Loading: "..asset.Name.." ["..i.."/"..#Assets.."]" 
end

print("Done loading.")

script.Parent.LoadingText.Textbox.Text = "Assets Loaded!"
wait(3)
Tween:Play()

I removed the Delete() action since I thought that might be the problem.

Explorer layout:
image

Thank you in advance!

1 Like

The issue is

local Tween = TweenService:Create(
	UIObjects,
	TweenInfo ,
	{script.Parent.LoadingText.BackgroundTransparency == 1 , script.Parent.LoadingText.Textbox.TextTransparency == 1}
)

Firstly, I’m not entirely sure that you can tween multiple objects at once like that

Secondly, you need to put just BackgroundTransparency = 1, instead of script.Parent.Loading.Text.BackgroundTransparency = 1. You only put the property name and the value

1 Like

I think it is because you aren’t putting just BackgroundTransparency in the Tween area.
here

local Tween = TweenService:Create(
	UIObjects,
	TweenInfo,
    {BackgroundTransparency = 1 , TextTransparency = 1}
)

also I don’t think you put == and you put = instead when setting a value for the properties
@SeargentAUS got to it first but this is just the code that I think might fix it.

1 Like

I edited the script according to the info you and @labra_doodle12 gave me and I get the new error now “Unable to cast Dictionary to TweenInfo

I also tried using only one UI object at a time, same result.

Script:

local TweenService = game:GetService("TweenService")
local LoadingTextTransparency = script.Parent.LoadingText
local Tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false)
local TweenLoadingTextTransparency = TweenService:Create(
	LoadingTextTransparency,
	TweenInfo ,
	LoadingTextTransparency.BackgroundTransparency == 1
)

I tried both with LoadingTextTransparency.BackgroundTransparency == 1 and 'BackgroundTransparency' = 1

1 Like

I guess I will try and replicate what you have and see if I can get it working.

2 Likes

You forgot this

{LoadingTextTransparency.BackgroundTransparency = 1}

That’s why you got the error. You didn’t make it as a table which caused the dictionary error.

1 Like

I think why it was giving you that error because you made the tweeninfo variable name Tweeninfo, but then you use it later as TweenInfo, with a capital i instead, and it didn’t throw an error in the editor, because putting just TweenInfo doesn’t do that. That solved the error with the dictionary.

But after doing that, another error comes up that I am trying to fix currently.

1 Like

What’s the error that’s coming up, maybe I could help.

1 Like

I did it!
Here is the revised script, works perfectly for me.

local ReplicatedFirst = game:GetService('ReplicatedFirst') 
local ContentProvider = game:GetService("ContentProvider")
-- tweening stuff
local TweenService = game:GetService("TweenService")
local UIObjects = {
	script.Parent.LoadingText,
	script.Parent.LoadingText.Textbox
}
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false)


local Assets = game:GetDescendants() 

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
ReplicatedFirst:RemoveDefaultLoadingScreen()

repeat wait() until game:IsLoaded()
for i = 1, #Assets do
	local asset = Assets[i]

	ContentProvider:PreloadAsync({asset})
	script.Parent.LoadingText.Textbox.Text = "Loading: "..asset.Name.." ["..i.."/"..#Assets.."]" 
end

print("Done loading.")

script.Parent.LoadingText.Textbox.Text = "Assets Loaded!"
wait(3)
for _, v in ipairs(script.Parent:GetChildren()) do
	if v:IsA("Frame") then
		local Tween = TweenService:Create(v, tweenInfo, {BackgroundTransparency = 1}):Play()
	else if v:IsA("TextLabel") then
			local Tween = TweenService:Create(v, tweenInfo, {BackgroundTransparency = 1 , TextTransparency = 1}):Play()
		end
	end
end

I tried it out, it said it was loading the name of the asset, and then after, it faded away. It looks pretty good :+1:

Edit: Turns out the text didn’t go invisible

1 Like

I tried that as well. It tells me that instead of } I got “=”

Players.Reinrexie.PlayerGui.LoadingScreen.LoadingScreenScript:11: Expected '}' (to close '{' at column 2), got '='
1 Like

Pretty weird. However, it seems that the solution for your inquiry had come so good luck!

1 Like

Has the text faded away for you? Everything works now, no errors, but the “Asset Loaded!” text is not fading away.

1 Like

use getdescendants instead
Sorry I didn’t think of that
And I mean in the part that loops through the screengui

2 Likes

Thank you so much, Calvin! You’ve helped me lots.

3 Likes

Your welcome, have a good day!

3 Likes

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