#efficient way to make sure no problems occur from things not being loaded yet

1 messages · Page 1 of 1 (latest)

coarse pecan
#

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!

solemn gust
#

i read like half of it so i would do “ContentProvider:PreloadAsync({object})”

coarse pecan
#

wdym you read like half of it

solemn gust
#

of your message

coarse pecan
#

alr well

#

do you mind reading it fully?

solemn gust
#

i did

coarse pecan
#

ty

#

so instead of doing :WaitForChild i should do what you suggested?

solemn gust
#

yes

coarse pecan
#

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?

coarse pecan
#

so how do loading screens work then usually?

#

like where they show

1/600 or something

solemn gust
#

they use contentprovider

coarse pecan
#

but how can they get that count of how much there is to load?

solemn gust
#

they do things like

coarse pecan
#

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)

solemn gust
#
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```
coarse pecan
#

how would it get the descendants without having to load them

#

or does getdescendants not work this way

solemn gust
#

it doesnt work that way

coarse pecan
#

so it basically gets like

#

an unloaded object

#

just the idea of it

#

or am i still misunderstanding

solemn gust
#

personally i haven't worked with loading screens for anything but it just loads the object in the game im pretty sure

slate trailBOT
#

studio** You are now Level 15! **studio

coarse pecan
#

huh

solemn gust
#

you can just read contentprovider documentation

coarse pecan
#

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?

solemn gust
#

well

#

i havent really thought of that

coarse pecan
#

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

solemn gust
coarse pecan
#

alright

#

i'll still wait for a person or two to come in and see what they have to say about loading screens

coarse pecan
#

im a little curious on something

solemn gust
#

huh

coarse pecan
#

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

solemn gust
#

well game:GetChildren() gives the first layer of children only and is faster

#

but :GetDescendants is in order and is slower

coarse pecan
#

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

solemn gust
#

you can do a loadingscreen

#

or

coarse pecan
#

local expectedChildren = 5

solemn gust
#

game.Loaded

coarse pecan
#

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?

solemn gust
#

sure

coarse pecan
#
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

slate trailBOT
#

studio** You are now Level 4! **studio

coarse pecan
#

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()

solemn gust
#

the game could be already loaded before that code runes

#

runs

#

do something like

#
if not game:IsLoaded() then
  game.Loaded:Wait()
end```
coarse pecan
#

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

coarse pecan
#

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

coarse pecan
#

ok

#

literally everything fixed itself when i put the local script in startercharacterscripts into starterplayerscripts

#

do you know why?

fervent flicker
#

i might be able to help ya

solemn gust
#

starterplayer runs once