Is this a good idea? (preloading asset system)

Basically, the preloading script is in replicatedfirst. It disables the player’s client-side scripts first (e.g. playerscripts, playerguiscripts), then after the character is added it disables the character’s scripts and then gets all the assets in the game and preloads them, after they’ve been preloaded the scripts are enabled. The reason i’m doing this is because the game has like over a hundred scripts and I can’t just manually go in and put preloadasync at the start for each one. Also disabling the scripts I thought ensures that all assets are loaded first before the scripts even run so that’s why I did it. is this a bad idea?

1 Like

Oh yeah disabling and enabling the scripts are also wrapped in pcalls with pcall retry logic because obviously enabling and disabling scripts you would never want to go wrong.

1 Like

No! This is a great idea! You won’t have to use wait() functions or repeat loops until the character has loaded when scripting! So you should definitely do this. But the script has to be the first one running… So that might be a problem. But if it works then it is 100% worth it. I should’ve thought about this earlier! :+1: :happy2:

Wow thanks man, I thought I was being really dumb and almost thought about getting rid of the script. Yeah I also made sure the script is the first one running by parenting it to replicatedfirst.

Alright that’s great!

30char

Is the blurred message meant to mean something? Or…?

Also I might wait until other people come and start giving their suggestions on this because I’m still not 100% sure it’s the best route.

I meant that there’s a minimum amount of characters…

Ohhhh I didn’t know people did that okay!

1 Like

Um one more thing though, for the disablingcharacterscripts thing. It still does wait until the character has loaded in like using player.Character or player.CharacterAdded:Wait() is that gonna be an issue?

some games have a loading screen, and in the loading screen they actually preload all assets.
then the loading screen goes away once all assets are loaded.

Now regarding your other comment where you are asking if CharacterAdded:Wait() is a problem.
If a script is in ReplicatedFirst, it will be the first ever client script to run.
this means that any object isn’t loaded in workspace yet, and the players’ character doesn’t exist yet.

in the roblox documentation they clearly state that yielding in a script in replicatedfirst is not recommended because you lose the advantage of running before anything else.
If you really need to yield, then consider putting it anywhere else except replicatedfirst.

quote from docs:

ReplicatedFirst is most commonly used to store LocalScripts and other objects that are essential for the game’s start. As the contents of ReplicatedFirst replicate to the client before anything else in the game, it is ideal for creating loading GUIs or tutorials.

For objects that do not need to be replicated first, developers should use the ReplicatedStorage container instead.

LocalScripts placed within ReplicatedFirst will run. This means code for custom loading screens or other ReplicatedFirst uses can be ran at the earliest possible point.

There a number of key considerations developers need to remember when running LocalScripts in ReplicatedFirst.

  • Its contents replicate before anything else in the game, meaning LocalScripts running in ReplicatedFirst will need to wait for any objects they require to replicate using Instance:WaitForChild()
  • Any objects that are to be used by a LocalScript in ReplicatedFirst should also be parented to ReplicatedFirst. Otherwise, they may replicate to the client late, yielding the script and negating the benefit of ReplicatedFirst.

source: ReplicatedFirst | Documentation - Roblox Creator Hub

hope this answers your question.

No, I don’t think so atleast. :+1:

That is a good idea @Amritss and is common practice in many games.

So what you’re saying is I’m smart? Ayeee.

So many games disable the client-side scripts and after the assets are preloaded they enable them?

Yeah I’m sure it’s good enough for whatever you were trying to do.

That is VERY unusual.

I don’t understand why you have to choose this approach. Unless you can give more context, this is pretty redudant. There is a reason why Instance:WaitForChild() exists. It yields the current thread until either the instance is found, or an infinite yield possible warning is printed.

From your code provided, it doesn’t help to justify your approach either. You cannot disable a server-sided script from a client script.

You should also consider reading @scavengingbot’s post. They provided a good point on when you should use LocalScripts in ReplicatedFirst.

Actually you can as long as its not in starterplayerscripts (which it shouldn’t be in there anyway but just in case there is one in there it’s disabled). So scripts in the workspace, startercharacter can be disabled.

What do you exactly mean by buggy code?

Who says that you cannot use the same function over and over? That’s like saying using :FindFirstChild() every time I need to find an object. As long as you know how to use a function correctly, it shouuldn’t result in negative performance.

???
Any scripts located in ServerStorage won’t run.

Of course it would stop working if you frequently enable/disable them because there may be scripts that depend on another script.

Did you forget the use of Instance:WaitForChild()?

I don’t really see the point of you making this Preloading Asset system. Perhaps you have misunderstood what is the purpose of ContentProvider service…

The service’s main use is to preload assets into a game. When a new asset such as a Decal or Sound is used in a game, Roblox will load the content associated with it from Roblox servers. In some cases, this can be undesirable for developers as it can lead to a delay before the content loads into the game.

You do not have to worry about scripts not being able to access or use an instance that has not been loaded at the time those scripts run. Everything will be loaded eventually on the client. ContentProvider is only useful if you wish to preload instances that can require time to fully load before using them in your experience.

2 Likes

No you cannot.

2 Likes