You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want a frame to fade out when loading assets is complete
What is the issue? Include screenshots / videos if possible!
It isn’t fading out and just getting destroyed at the end
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
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
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()