Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is happening with... LoadingGUIs?

Asked by
davness 376 Moderation Voter
9 years ago

I just made a script to do a loading script. So I'm asking two questions:

local assets = game.ContentProvider.RequestQueueSize -- it loads immediately the total assets the game has to load and stores it. Doesn't update.--

script.Parent:RemoveDefaultLoadingScreen()

local frame = game.ReplicatedFirst.LoadingGUI:Clone()
frame.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")


local speed = 0.1 -- It stores the rotation speed --

while game.ContentProvider.RequestQueueSize > 0 and speed < 50 do
    local assetys = game.ContentProvider.RequestQueueSize -- it loads immediately the assets the game still didn't load. Updates every loop. --
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    speed = (speed*2) -- Doubles the rotation speed (until it reaches the speed of 50)
    wait()
    frame.Frame.LoadingLabel.Text = "Loading assets... Progress: "..(((assets - assetys)/assets)*100).."%" 
    -- If there were 10000 instances to load and 3500 are still loading: (((1000-3500)/10000)*100) == (6500/10000)*100 == 0.65*100 == 65% complete --
    -- Then, of these 10000 instances, 2650 are unloaded yet: (((1000-2650)/10000)*100) == (7350/10000)*100 == 0.735*100 == 73.5% complete --
end

while game.ContentProvider.RequestQueueSize > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.LoadingLabel.Text = "Loading assets... Progress: "..(((assets - assetys)/assets)*100).."%"
    wait()
end

frame.LoadingLabel.Text = "Game Loaded. Preparing to spawn..."

while speed > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    speed = (speed-.2) -- It will gradually slow down the rotation speed until it reaches zero.
    wait()
end

wait (2.5)
frame.Parent = nil

Q1: Line 1 - Will the assets value update when the QueueSize updates?

Q2: I stored the GUI on ReplicatedFirst. What happened? The GUI appeared as a StarterGUI. SO I want to do an important question: Can we make the loading of Players first, then Workspace?? On other words, why is the LoadingScreen just loading when everything is loaded?? Can we solve it? :)

0
Why are you using two while loops inside a while loop inside a while loop??? You know you can only run one while loop at a time unless you use another thread? NotsoPenguin 705 — 9y
0
I edited the script. Is it better now? davness 376 — 9y
0
Still a lot of while loops. Try using coroutines. Shawnyg 4330 — 9y
0
I'll attempt to fix the script myself. I think i know what's wrong. Marios2 360 — 9y

1 answer

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
9 years ago

Your GUI failed to load because.... it was never a GUI. Inception Sound Effect

Roblox for some reason doesn't allow a ScreenGui inside ReplicatedFirst, so you must make one yourself in the LocalScript.

Instead of ScreenGui, you used a Frame. So i made the script add a ScreenGui inside the PlayerGui and put your loading GUI pack inside said ScreenGui.

You cannot load Players before Workspace (only the developers can change that, and only they know if it indeed loads like that) and it's not that either.

As for Q1, the assets variable never updates because you only request it once.

So here's your fixed script - i didn't test it in Studio but it should function:

(I wrote this inside Studio but i didn't recreate your GUI to see if it works fully. You should be able to fix any GUI issues yourself.)

script.Parent:RemoveDefaultLoadingScreen()  -- Just in case, this goes first
local assets = game.ContentProvider.RequestQueueSize -- The existing assets at first. It never updates as you request it only once.

local base = Instance.new("ScreenGui") -- To get visuals, you need this first. Even the Wiki mentions it (http://wiki.roblox.com/index.php?title=Custom_loading_screen). This is your main mistake.
base.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local frame = game.ReplicatedFirst.LoadingGUI:Clone()
frame.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui

--One more note: For commenting, you don't need a "--" at the end of the comment.
--Comments automatically end at the end of the line they are placed on.
--Below this point are your comments.

local speed = 0.1  -- It stores the rotation speed --

while game.ContentProvider.RequestQueueSize > 0 and speed < 50 do
    local assetys = game.ContentProvider.RequestQueueSize -- it loads immediately the assets the game still didn't load. Updates every loop. --
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    speed = (speed*2) -- Doubles the rotation speed (until it reaches the speed of 50)
    wait()
    frame.Frame.LoadingLabel.Text = "Loading assets... Progress: "..(((assets - assetys)/assets)*100).."%" 
    -- If there were 10000 instances to load and 3500 are still loading: (((1000-3500)/10000)*100) == (6500/10000)*100 == 0.65*100 == 65% complete --
    -- Then, of these 10000 instances, 2650 are unloaded yet: (((1000-2650)/10000)*100) == (7350/10000)*100 == 0.735*100 == 73.5% complete --
end

while game.ContentProvider.RequestQueueSize > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.LoadingLabel.Text = "Loading assets... Progress: "..(((assets - assetys)/assets)*100).."%"
    wait()
end

frame.LoadingLabel.Text = "Game Loaded. Preparing to spawn..."

while speed > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre.Rotation = (script.Parent.Rotation-speed)
    speed = (speed-.2) -- It will gradually slow down the rotation speed until it reaches zero.
    wait()
end

wait(2.5)
frame.Parent = nil

Tada! I hope this actually helps! Good luck on further development!

Ad

Answer this question