I have been working on multiple games for awhile now, and the main issue across a lot of them is player values that are needed for the game to run. For the longest time I have been doing this when a player joins:
--Giving values to the player
local Laps = Instance.new("IntValue") --making the value
Laps.Name = "Laps" --giving the name
Laps.Value = 1 --giving the value
Laps.Parent = player --and assigning it a parent
But as my games expand and grow much bigger, I end up having dozens of these values, and this becomes pretty memory intensive and does not seem efficient. I know that the starterplayerscripts replicate scripts to the player, but cannot be seen by the server, so that wouldn’t work, startercharacterscripts replicate it to the character, but reset every time which creates a multitude of issues in round based systems as well as slows the game down in general. The backpack is another option, but that resets as well. The playergui resets AND can’t be seen by the server so that is definitely out.
Is there a folder I can add objects to that will automatically replicate values straight into the player?
In my game, I have the same issue. It is also compounded by the fact that I need similar values for my NPCs. My way of working with things is parenting the enture hierarchical structure (nested scripts inside values inside folders) to something and cloning that into the hamanoid. When a non NPC character dies I move the structure to them to the player and disable all scripts. Repeat when the character respawns.
Not sure if this is the best way, and I consider different approaches all of the time.
You can create a folder and fill it with values, then store it somewhere (ReplicatedStorage or ServerStorage). When a player’s character is created, clone the folder and place that into the character, updating whatever values you want.
Though what I’d do is just create folders for every player, naming each by player names, store the folders on the server, and then have the server update the values. If you need new values just run a function to reset them.
You could use Attributes instead, they’re more performance friendly as they aren’t instances, and is less lines to write out.
local Laps = Instance.new("IntValue") --making the value
Laps.Name = "Laps" --giving the name
Laps.Value = 1 --giving the value
Laps.Parent = player --and assigning it a parent