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
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:
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.