I have been storing them in the PlayerGui but it seems to be a little messy.
Should they be in PlayerScripts/ReplicatedFirst or does it even matter?
i am asking this because i want to clean up my scripts to make them more organized.
I have been storing them in the PlayerGui but it seems to be a little messy.
Should they be in PlayerScripts/ReplicatedFirst or does it even matter?
i am asking this because i want to clean up my scripts to make them more organized.
StarterPlayerScripts, PlayerGui, wherever you want. I suggest StarterPlayerScripts if you need it consistent, StarterCharacter if you need it when they respawn, and PlayerGui if it’s Gui related. Your choice entirely.
If you need your LocalScript to start running as quickly as possible, use ReplicatedFirst.
If it’s a script which handles everything and isn’t supposed to be reset, use StarterPlayerScripts.
The purpose of ReplicatedFirst is for the script to replicate before anything else (useful for things like loading screens), but if that behavior isn’t needed, then it wouldn’t really matter. (besides having to using WaitForChild alot more frequently)
I usually don’t store scripts in PlayerGui, as it is a container which gets reset every time the player gets a new character, and that the character must be loaded in atleast once. (adding a ScreenGui to PlayerGui to just prevent the scripts from being refreshed also seems pointless)
ReplicatedFirst - For local scripts which should be ran before everything is loaded in.
StarterPack, StarterCharacterScripts - For any local script which should run each time the character is loaded.
StarterGui - For any local script which would work directly with the UI in StarterGui.
StarterPlayerScripts - For any local script which should just be run once and doesn’t need the behavior of ReplicatedFirst.
Why don’t you just run all local scripts in ReplicatedFirst?
That’s not the point of ReplicatedFirst. It should only be used for code that needs to be ran before the game loads. LocalScripts are not among that category, save for initialisation processes.
Local Scripts in ReplicatedFirst are run before everything in things like Workspace or ReplicatedStorage is replicated, so you have to use WaitForChild whenever you want to access anything outside of ReplicatedFirst that you added.
i.e
local Baseplate = workspace.Baseplate
Would become
local Baseplate = workspace:WaitForChild"Baseplate"
There also isn’t anything significantly better about having local scripts in ReplicatedFirst over StarterPlayerScripts if it doesn’t need to run before everything is loaded.
All my games use StreamingEnabled so it doesn’t really make any difference for me
Does this increase loading/initialisation times?
Nope, all ReplicatedFirst does is run client code before game.Loaded fires and makes it’s children among the first of items replicated, hence it’s name. Loading is a separate process unhindered by ReplicatedFirst.
Canonically, no code aside from initialisation code should be in ReplicatedFirst. Keeping a clear codebase helps you in the long run. There’s no benefit to keeping your client code in ReplicatedFirst either if it isn’t processes to be ran before game.Loaded fires.
For me, I make it a habit to have most of my code be in StarterPlayerScripts and ServerScriptService (for the server), respectively.