Frame isn't fading out

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

    I want a frame to fade out when loading assets is complete

  2. What is the issue? Include screenshots / videos if possible!

    It isn’t fading out and just getting destroyed at the end

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

    I tried to change the background transparency of the frame in a for loop but that didnt seem to work, also tried to change it using tween which also didnt work as seen below.

The frame is a child of a “Loading” screen gui that is a child of the script, also the Frame has a child “Text label” which is just a text label used for showing the % of completeness

local contentprovider = game:GetService("ContentProvider")
local ui = script:WaitForChild("Loading"):Clone()

repeat wait() until game:IsLoaded()

local assets = game:GetDescendants()
local maxassets = #assets

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

ui.Parent = plrgui

for i, assetsToLoad in assets do
	contentprovider:PreloadAsync({assetsToLoad})
	local value = i/maxassets
	value = value * 100
	value = math.floor(value)
	ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = value.."%"
end
wait(1)
ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = "Assets loaded"
game.ReplicatedStorage.Loaded:FireServer()
wait(3)
local Frame = script:WaitForChild("Loading"):WaitForChild("Frame")
local TweenService = game:GetService("TweenService")
TweenService:Create(
	Frame,
	TweenInfo.new(2),
	{BackgroundTransparency = 1}
):Play()

ui:Destroy()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You need to use the Tween.Completed event to wait for the Tween to finish playing like so:

local contentprovider = game:GetService("ContentProvider")
local ui = script:WaitForChild("Loading"):Clone()

repeat wait() until game:IsLoaded()

local assets = game:GetDescendants()
local maxassets = #assets

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

ui.Parent = plrgui

for i, assetsToLoad in assets do
	contentprovider:PreloadAsync({assetsToLoad})
	local value = i/maxassets
	value = value * 100
	value = math.floor(value)
	ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = value.."%"
end
wait(1)
ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = "Assets loaded"
game.ReplicatedStorage.Loaded:FireServer()
wait(3)
local Frame = script:WaitForChild("Loading"):WaitForChild("Frame")
local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(
	Frame,
	TweenInfo.new(2),
	{BackgroundTransparency = 1}
)
tween:Play()
tween.Completed:Wait()

ui:Destroy()

I would also recommend learning how to organise your code, the benefit being the more neat your code is the less likely you are to experience bugs. I recommend this resource to learn how: Roblox Lua Style guide

The screen still isn’t fading. Here’s a video to better understand the issue: Untitled - Clipped with Medal.tv

This might sound strange but, are you sure the Tween is working on the correct Frame? It could be the case that the Tween is currently changing the transparency of the wrong Frame inside of your Gui

Edit: @This100Times As a matter of fact I just noticed that the Tween is currently changing the transparency of the original Frame that’s parented to the LocalScript instead of the Frame that’s inside of the player’s PlayerGui

1 Like

image
The script should be changing the transparency of the frame since frame = script.Loading.Frame

Oh, then I should change the frame to frame = game.Players.LocalPlayer.PlayerGui.Loading.Frame ?
Edit: Yes, this worked. Thanks a lot!

1 Like

It should also work if you change it to Frame = ui:WaitForChild("Frame") like so:

local contentprovider = game:GetService("ContentProvider")
local ui = script:WaitForChild("Loading"):Clone()

repeat wait() until game:IsLoaded()

local assets = game:GetDescendants()
local maxassets = #assets

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

ui.Parent = plrgui

for i, assetsToLoad in assets do
	contentprovider:PreloadAsync({assetsToLoad})
	local value = i/maxassets
	value = value * 100
	value = math.floor(value)
	ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = value.."%"
end
wait(1)
ui:WaitForChild("Frame"):WaitForChild("TextLabel").Text = "Assets loaded"
game.ReplicatedStorage.Loaded:FireServer()
wait(3)
local Frame = ui:WaitForChild("Frame")
local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(
	Frame,
	TweenInfo.new(2),
	{BackgroundTransparency = 1}
)
tween:Play()
tween.Completed:Wait()

ui:Destroy()
3 Likes

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