Hey all! I am currently using StringValues, BoolValues, and IntValues to save my player data, and wondered if that was efficient! Thanks!
It depend on your type of data. If you are saving coins, xp, levels, etc., a number value would be fine. If you have inventory, you should use a table.
Overall, I would recommend using tables instead. Strings are useful for storing one thing, but once you have more than one item in the same category, it can get complicated without using tables. For example:
local Data = "SMG" -- This is fine
local Data2 = {
Weapon = "SMG" -- Unnecessary
}
In this situation, using a string makes sense, since itβs just one value. However, when you have multiple, such as a set of weapons, it can get complicated, and it gets hard to store metadata. For example:
local Weapons = "SMG|Sniper|Pistol"
local WeaponList = string.split(Weapons,"|") -- Not good
local BetterWeaponList = {
SMG = {
Firerate = 50
ReloadTime = 1.35
}
Sniper = {
Firerate = 0.35
ReloadTime = 2
}
Pistol = {
Firerate = 10
ReloadTime = 1.25
}
}
So far Iβve only talked about storing static data, but the same thing applies to PlayerData. For example:
local PlayerData = {
-- These would be individual keys in a datastore, not all in one table
UserId_284833 = {
Coins = 50
Gems = 10
}
UserId_1039244 = {
Coins = 13000
Gems = 200
}
UserId_9382342 = {
Coins = 35000
Gems = 1350
}
}
You typically want to store your player data in tables, since theyβre much easier to work with than strings, and probably more efficient (if you have to split the data and organize it manually, itβs probably less efficient than just having it organized the second you receive it). However, I would advise against making your own data saving system, as itβs been done for you extremely well in community resources. I would recommend either Datastore2 or ProfileService, since they have systems to prevent data loss. While they may seem more complex at first, itβs worth it.
intValues instead would be better
Itβs totally fine! In fact, itβs one of the best ways to save data (itβs much better than using int values ββactually), if youβre saving a lot of values, be sure to use a table!
βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ βββ