Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

0

hmm ok

0

it's still only 5 images total

1 answer

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.

4 comments

0

there are actually only 5 image labels

0

but thanks for the help

0

just found out the problem is that some the images aren't even loading.

0

like IsLoaded never gets enabled

This discussion is preserved as it was. New answers, comments, and votes are closed.