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

ReplicateFirst: LoadingGUI isn't loading properly. Help?

Asked by
davness 376 Moderation Voter
9 years ago

Hello. Because i cannot explain the situation by text, i just made a video to do that. You can see it here:

https://www.youtube.com/watch?v=kPku4DgPA7g

Here's a copy of the current scrpt i'm using:

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.2 -- 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.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.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.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.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.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.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

Thank you.

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem

You have 3 while loops on line 13, line 24, and line 34. Due to the multitude of while loops, any code past the first one will not run.

How to Fix

There are two ways I can think of fixing this

  • Use coroutines to make all the while loops occur at the same time

    coroutines return the 'thread' datatype, when the script reads a thread it splits off into two segments - the first being the rest of the code, and the second being the thread - and runs them both in unision. Therefore eradicating any yield betwixt the two. In basic terms, it will remove any waits in between the thread and the rest of the code.

    So to use this to your advantage? Use the coroutine.wrap function to 'wrap' your first two while loops in a thread. The coroutine.wrap function returns a callable function containing the thread so you would do coroutine.wrap(function() [code] end)().

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.2 -- It stores the rotation speed --

coroutine.wrap(function() --wrap the while loop

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.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.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

end)() --end the thread function and call it

--Repeat

coroutine.wrap(function()

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

end)()

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

while speed > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.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

  • Combine all your while loops, and have conditionals to determine what actions to take

    This method is much more preferable, as it will shorten your code and effeciency. And it's not good practice to dwell on coroutines

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.2 -- It stores the rotation speed --

while wait() do
    if game.ContentProvider.RequestQueueSize > 0 then
        if speed < 50 then
            local assetys = game.ContentProvider.RequestQueueSize
                frame.Frame.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
             frame.Frame.MovingTyre2.Rotation = (script.Parent.Rotation+speed)
                speed = (speed+.2)
                wait()
                frame.Frame.LoadingLabel.Text = "Loading assets... Progress: " ..(((assets - assetys)/assets)*100).."%" 
        else
            local assetys = game.ContentProvider.RequestQueueSize
                frame.Frame.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
                frame.Frame.MovingTyre2.Rotation = (script.Parent.Rotation+speed)
                frame.Frame.LoadingLabel.Text = "Loading assets... Progress: " ..(((assets - assetys)/assets)*100).."%"
                wait()
        end
    else
        break
    end
end

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

while speed > 0 do
    local assetys = game.ContentProvider.RequestQueueSize
    frame.Frame.MovingTyre1.Rotation = (script.Parent.Rotation-speed)
    frame.Frame.MovingTyre2.Rotation = (script.Parent.Rotation+speed)
    speed = (speed-.2)
    wait()  
end

wait (2.5)
frame.Parent = nil
0
It still does not work. davness 376 — 9y
Ad

Answer this question