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

I'm having problems with my loading screen script, it seems to be stuck. [?]

Asked by 7 years ago

Hello, I am making a loading screen for my game and I ran into a problem. This loop is supposed to check if all of the GUI components are loaded in on the client side. The thing is it never loads. In my game it's stuck at 3 out of 17 in the player GUI, there are three "Images", not 17. I have looked at my script and don't really see anything wrong. It's in a LocalScript if that helps.

local Player = game.Players.LocalPlayer

local Images, LoadedImages = 0, 1

while Images ~= LoadedImages do
    wait()
    local Images = 0
    local LoadedImages = 0
    function IsItLoaded(item)
        for _, object in pairs(item:GetChildren()) do
            print(object.Name, " OK.")
            if object:IsA("ImageLabel") or object:IsA("ImageButton") then
                print(object.Name, " IS AN IMAGE.")
                Images = Images + 1
                if object.IsLoaded then
                    LoadedImages = LoadedImages + 1
                end
            end
            if #object:GetChildren() > 0 then
                print(object.Name, " HAS CHILDREN.")
                IsItLoaded(object)
            end
        end
        print(LoadedImages,"out of", Images)
        return Images, LoadedImages
    end
    IsItLoaded(game.Players.PlayerGui)
end
0
hmm ok connor12260311 383 — 7y
0
it's still only 5 images total connor12260311 383 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I believe the problem is that you have 17 ImageLabels/ImageButtons, even though you only use 3 of them to show an image. If the print(object.Name, " IS AN IMAGE.") shows up a total of 17 times, that would confirm it. The fix is to change line 15 to also consider if object has an image in the first place. If it has no image (ex, object.Image == ""), you shouldn't increase Images, nor check to see if it's loaded. (Note that an object with no image has IsLoaded == false.)

Scripting tips:

  • Don't declare the same variable local multiple times. Lines 7-8 makes line 3 unnecessary.
  • Put your function outside the loop, generally speaking. You don't need to have lua re-initialize the function every loop iteration (specifically, it'll store the existence of the "new" local variables on lines 7-8 with the function). The performance difference is negligible, but the clarity to your code is important (though this matters more in larger loops/scripts). You'll have to declare the local variables Images/LoadedImages above the function for it to work. In the while loop, you can reset them by doing Images = 0 and LoadedImages = 0

If it's still not working, your print statements are good, but you might also put one after line 15. You might also change it from object.Name to object:GetFullName(). Then you can figure out which objects are considered to be an Image and which ones are considered loaded.

0
there are actually only 5 image labels connor12260311 383 — 7y
0
but thanks for the help connor12260311 383 — 7y
0
just found out the problem is that some the images aren't even loading. connor12260311 383 — 7y
0
like IsLoaded never gets enabled connor12260311 383 — 7y
Ad

Answer this question