for instance, let's say i'm looping through a folder as the game loads, i want to make sure the folder is loaded fully. the best answer im seeing online is have a loading screen that is intentionally at least a couple of seconds long to make sure everything loads. is this an efficient solution? if i do make a loading screen, i want to make sure that it doesn't wait for any longer than it has to, and disappears once all the objects are loaded, but how can i make sure that happens? any other solutions are also welcome. thank you!
#efficient way to make sure no problems occur from things not being loaded yet
1 messages · Page 1 of 1 (latest)
i read like half of it so i would do “ContentProvider:PreloadAsync({object})”
wdym you read like half of it
of your message
i did
yes
alright
if i were to make a loading screen to prevent having to do anything like that, how can i wait until all objects are loaded and have a nice counter?
uhh
nothing else really
so how do loading screens work then usually?
like where they show
1/600 or something
they use contentprovider
but how can they get that count of how much there is to load?
they do things like
and for instance, how can they know when to provide the user with something like "skip loading" (as in, the only objects left to load are images or such)
local assets=game:GetDescendants()
for i=1, #assets do
local asset=assets[i]
ContentProvider:PreloadAsync({asset})
--i is amount of assets and #assets is total amount of assets
end```
how would it get the descendants without having to load them
or does getdescendants not work this way
it doesnt work that way
so it basically gets like
an unloaded object
just the idea of it
or am i still misunderstanding
personally i haven't worked with loading screens for anything but it just loads the object in the game im pretty sure
** You are now Level 15! **
huh
thanks
so
if i do this in a loading screen
whenever i'm in a local script
i'll basically never have to wait for child or find first child again?
yea this is quite complex
i'll wait for another person or two to come in and give their opinion and then i'll come up with something to do
alright
i'll still wait for a person or two to come in and see what they have to say about loading screens
im a little curious on something
huh
there has been a recent instance where i've used GetChildren() on a folder and it hasn't given me all of them because they're not loaded, right
but on a tutorial for a loading screen
i see
local assets = game:GetChildren()
i'm not sure how this doesn't encounter the same issue
well game:GetChildren() gives the first layer of children only and is faster
but :GetDescendants is in order and is slower
yeah well
when i did :GetChildren() on a folder, it didn't give me all of them
they weren't loaded
i had to do task.wait(1)
or, if i had a number like
local expectedChildren = 5
game.Loaded
this didn't work
i tried repeat task.wait() until game:IsLoaded()
same issue
it loaded like only the first four
so i'm not sure how in this instance it's fine but in the folder i had, it's not
should i provide the code?
sure
local serverStorage = game:GetService("ServerStorage")
local buttonPrefab = serverStorage:WaitForChild("Prefabs"):WaitForChild("ButtonPrefab")
local buttonLocations = game.Workspace:WaitForChild("ButtonLocations")
local buttonFolder = game.Workspace:WaitForChild("Buttons")
repeat task.wait() until game:IsLoaded() -- doesn't work
local firstButton = true
for _, buttonLocation in ipairs(buttonLocations:GetChildren()) do
local button = buttonPrefab:Clone()
if firstButton then
button:WaitForChild("Highlight").Enabled = true
firstButton = false
end
button.Parent = buttonFolder
button.Name = buttonLocation.Name
button.Position = buttonLocation.Position - Vector3.new(0, buttonLocation.Size.Y / 4, 0)
end
for context, what i'm doing here is that i have a object that represents where a button should be cloned into
** You are now Level 4! **
then, i'm trying to loop through all of them and just put a button prefab there
all of those are contained in buttonLocations
and you can see i'm doing
buttonLocations:GetChildren()
the game could be already loaded before that code runes
runs
do something like
if not game:IsLoaded() then
game.Loaded:Wait()
end```
i found some success with
repeat task.wait() until #buttonLocations:GetChildren() > 0
but this doesn't load all of them
with that code, now none of them load
it's very odd
what my goal is is
i don't want to have to mess around with any of this stuff in future
i want a loading screen that makes sure everything is loaded and then i can just assume things are loaded in future
at least client side
i'm not sure how it works server side
but it's weird how stuff like this happens
as you can see
some of these button location blocks
on the right side, aren't hidden
as i have
local buttonLocations = game.Workspace:WaitForChild("ButtonLocations")
repeat task.wait() until #buttonLocations:GetChildren() > 0
print(#buttonLocations:GetChildren())
for _, part in ipairs(buttonLocations:GetChildren()) do
part.Transparency = 1
end
in a local script, to hide it from the player as they load in
if i add in a task.wait(1) then it fixes everything
this code works in the local script
not in a server one though
actually i lied
it only helped the previous line i had
repeat task.wait() until #buttonLocations:GetChildren() > 0 on its own loaded most but not all
if not game:IsLoaded() then
game.Loaded:Wait()
end
doesn't work on its own
but together, they work
and load all of them
but who knows if that'll work for more
i just want a way to have a loading screen that for sure loads everything, and then i can have a value once i'm sure that everything is loaded called IsLoaded and set that to true, and i can just wait for that value before doing anything like this
because game:IsLoaded() does not seem to do that
also, the tutorial i'm watching doesn't seem to cover this instance
or specific problem
ok
literally everything fixed itself when i put the local script in startercharacterscripts into starterplayerscripts
do you know why?
startercharacter resets the script everytime the character respawns n stuff
starterplayer runs once