I am sorry if the title is very vague. I do not know what to name it. So I made a GUI that pops up when you step on a brick. In the GUI, there is a “loading” screen. It takes about 4 seconds to load and then it fades into some text. I tried the GUI out in studio and it worked fine. I scripted it so when you step on the brick, it clones the GUI and then pops up. I tested it out in-game but when I test it out in-game, it does not show the loading screen. It just shows the text. Can you guys help me? Is it because it loads on its own?
Here is the script for the loading:
local BarProgress = 0
local Background = script.Parent.Parent
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
Background.Visible = false
end)
while wait() do
BarProgress = BarProgress + 0.5
script.Parent.Size = UDim2.new(BarProgress/100, 0, 0.1, 0)
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress*2).."%")
if BarProgress == 50 then
wait(1)
while wait() do
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.08
script.Parent.Parent.BarBackground.BackgroundTransparency = script.Parent.Parent.BarBackground.BackgroundTransparency + 0.08
script.Parent.Parent.LoadingText.TextTransparency = script.Parent.Parent.LoadingText.TextTransparency + 0.08
if script.Parent.BackgroundTransparency >= 1 then
script.Parent.Parent.AfterText.Visible = true
wait(1)
script.Parent.Parent.Done.Visible = true
script.Parent.Parent.TextButton.Visible = true
end
end
end
end
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
Background.Visible = false
end)
And here is the script that clones the GUI:
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if debounce then return end
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
if Player then
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = Player.PlayerGui
debounce = true
end
end)
I don’t find any issues in the code (at least in the clone brick). I guess the script just won’t fire after its cloned to the player. Maybe activate it with the brick script with something like:
-- Loading Script --
local BarProgress = 0
local Background = script.Parent.Parent
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
Background.Visible = false
end)
script.Parent.Activate.Value.Changed:Connect(function() -- You first need to create a bool value in the GUI and call it "Activate"
while wait() do
BarProgress = BarProgress + 0.5
script.Parent.Size = UDim2.new(BarProgress/100, 0, 0.1, 0)
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress*2).."%")
if BarProgress == 50 then
wait(1)
while wait() do
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.08
script.Parent.Parent.BarBackground.BackgroundTransparency = script.Parent.Parent.BarBackground.BackgroundTransparency + 0.08
script.Parent.Parent.LoadingText.TextTransparency = script.Parent.Parent.LoadingText.TextTransparency + 0.08
if script.Parent.BackgroundTransparency >= 1 then
script.Parent.Parent.AfterText.Visible = true
wait(1)
script.Parent.Parent.Done.Visible = true
script.Parent.Parent.TextButton.Visible = true
end
end
end
end
end)
-- Server Script --
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if debounce then return end
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
if Player then
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = Player.PlayerGui
GuiClone.Activate.Value = true -- Activate the scipt via bool value
debounce = true
end
end)
I can’t say if that’s a good way to do it. You can also try it by disabling the script and enabling it with the brick script again!
Mousebutton1Click will only fire if a mouse clicks it. It is better to use Activated. Have you checked the PlayerGui to see if the loading screen is in there?
I’m not sure what exactly is causing the issue in your code.
I have noticed that you use a lot of loops for transition animations though. You should get familiar with TweenService! It’s very useful for animations like yours. Here are a few links that you can check out:
--// Loading Script
local BarProgress = 0
local Background = script.Parent.Parent
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
local gui = Background:FindFirstAncestorOfClass("ScreenGui")
gui:Destroy()
end)
while wait() do
BarProgress = BarProgress + 0.5
script.Parent.Size = UDim2.new(BarProgress/100, 0, 0.1, 0)
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress*2).."%")
if BarProgress == 50 then
wait(1)
while wait() do
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.08
script.Parent.Parent.BarBackground.BackgroundTransparency = script.Parent.Parent.BarBackground.BackgroundTransparency + 0.08
script.Parent.Parent.LoadingText.TextTransparency = script.Parent.Parent.LoadingText.TextTransparency + 0.08
if script.Parent.BackgroundTransparency >= 1 then
script.Parent.Parent.AfterText.Visible = true
wait(1)
script.Parent.Parent.Done.Visible = true
script.Parent.Parent.TextButton.Visible = true
end
end
end
end
--// Server Script
local Brick = script.Parent.SCIParts.Touch
local debounce
Brick.Touched:Connect(function(other)
if debounce then return end
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
if Player then
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = Player.PlayerGui
debounce = true
spawn(function()
wait(2) --DEBOUNCE TIME
debounce = false
end)
end
end)
I would try to use the tween service. I made that script. It changes the size correctly for every device.
It will save the old size in a variable and calulate the tween size if needed:
local BarProgress = 0
local oldSize1 = script.Parent.Size.X.Scale
local oldSize2 = script.Parent.Size.X.Offset
local oldSize3 = script.Parent.Size.Y.Scale
local oldSize4 = script.Parent.Size.Y.Offset
script.Parent.Size = UDim2.new(0, 0, oldSize3, oldSize4)
script.Parent:TweenSize(UDim2.new(oldSize1, oldSize2, oldSize3, oldSize4), 1, 1, 4)
for count = 1, 100 do
wait()
BarProgress = BarProgress + 1
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress).."%")
end
wait(1)
Here is the full version of the Local Script:
-- Loading Script --
local Background = script.Parent.Parent
local BarProgress = 0
local oldSize1 = script.Parent.Size.X.Scale
local oldSize2 = script.Parent.Size.X.Offset
local oldSize3 = script.Parent.Size.Y.Scale
local oldSize4 = script.Parent.Size.Y.Offset
script.Parent.Size = UDim2.new(0, 0, oldSize3, oldSize4)
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
Background.Visible = false
end)
script.Parent.Activate.Value.Changed:Connect(function() -- You first need to create a bool value in the GUI and call it "Activate"
script.Parent:TweenSize(UDim2.new(oldSize1, oldSize2, oldSize3, oldSize4), 1, 1, 4)
for count = 1, 100 do
wait()
BarProgress = BarProgress + 1
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress).."%")
end
wait(1)
while wait() do
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.08
script.Parent.Parent.BarBackground.BackgroundTransparency = script.Parent.Parent.BarBackground.BackgroundTransparency + 0.08
script.Parent.Parent.LoadingText.TextTransparency = script.Parent.Parent.LoadingText.TextTransparency + 0.08
if script.Parent.BackgroundTransparency >= 1 then
script.Parent.Parent.AfterText.Visible = true
wait(1)
script.Parent.Parent.Done.Visible = true
script.Parent.Parent.TextButton.Visible = true
end
end
end)
VERY IMPORTANT: Keep in mind that the loading bar needs to have the final size at the beginning. It will automatically reset after starting the game.
Thank you for writing that for me but I am still having the same issue. If you wait around in the game and then try it out it does not show the loading frame. It just goes right to the text.
That is very weird. It looks like the loading screen and the background transparency animation were done before the clone. Therefore I suspect that it has already taken place in the workspace part. One way to avoid this is to put the gui into the replicated storage.
But that’s just a guess. And another embarrassing side question: is it definitely a local script that executes the code?
I think I fixed it! I did what you said. So what I did, I cloned it into replicated storage right when you start. Then, when you step onto the brick, it clones it to the player gui. Thank you so much!