Best way to save Player Data

hi guys i’m making a game where i have to save some rarities that a player has unlocked, for example, playerA has common, rare and epic;
what would be the best way to save it?
For some other systems i sometimes have to check if a player has a rarity, so I’m undecided between this 2 types of tables:

--type 1
local myTable = {
    common = true,
    rare = true,
    epic = true
}

or

-- type 2
local myTable = {
    "common",
    "rare",
    "Epic"
}

probaly the type2 could have less problems but to search a rarity i have to iterate all the table to search it, with the type1 i could just use FindFirstChild

local PlayerData = {
-- all the players stuff gems, money etc....
Rarities_unlocked = {
  ["common"] = false,
  ["rare"] = false,
  ["epic"] = false
  }
}

yes I wanted to write this as type1, I made a mistake, moreover couldn’t this formatting cause some problems at the datastore level?

1 Like

oh yeah sorry i didn’t read the “probaly the type2 could have less problems but to search a rarity i have to iterate all the table to search it, with the type1 i could just use FindFirstChild”

then the type 2 is better

1 Like

You can use table.find(myTable, rarity) for type 2 tho. :thinking:

1 Like

“You can use table.find(myTable, rarity) for type 2 tho”
i didn’t knew that, ty man

2 Likes

then what abt this? this only works for type 1

if Rarities_unlocked[RARITY_NAME] then

end
1 Like

yes i did exacly like that, i wonder if it would cause some data loss, i’m not really into backend things

Okay, let’s put words on things.

For the 1st one you’d do:
myTable[SOMETHING] or myTable.SOMETHING

while for type 2 you’d do something like:
table.find(myTable, SOMETHING) or myTable:find(SOMETHING)

The first one is a dictionnary while the 2nd one is an array, to check rarity in that case, I’d rather use the first one as I believe it is easier to do if myTable.rare than than if myTable:find("rare") then but both will lead to the same result, the 2nd one is like saying: [1] = "common", [2] = "rare" , [3] = "Epic"

(btw, you put a capital E for type 2, be careful if you’re using this in an actual script)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.