How to save the "Unlocked" status with the weapon name to DataStore?

Hi Developers! :wave:

I’m making a new weapon saving system, and I’ve encountered a pretty big problem: I don’t know how to save the “Unlocked” status for all weapons, which is a bool value. Is it possible to save like a table consisted of the weapon name and this bool value?

Any help is really appreciated! :hidere:

1 Like

you can do something like

data = {
  unlocked = {
    sword = true
    gun = true
  }
  otherstuff = {}
}
1 Like

And I’m just gonna save this like a regular table?

yes it is just a regular table

1 Like

I would solve this issue by setting the datastore to a blank table, then inserting a table of all the information you want to store using the UpdateAsync() function, the code would probably look like this

local gunData = game:GetService("DataStoreService"):GetDataStore("GunAtts")
local success, err = pcall(function()
	gunData:UpdateAsync("Key", function(oldVal)
		local newGunData = {}
		table.insert(newGunData, "Table")
		return newGunData
	end)
end)
if success then print("Yippee!") end
1 Like

why not just use :setasync if youre not using the oldval from the update

and storing in string keys is more readable

1 Like

Ah thats true, If you just wanted to change the table entry then this would work, since GunAtts would only have one entry you could also just store one table

1 Like

I’ll test all of them tomorrow and I’m gonna put the solution thing to the most efficient one

Data = {
    Weapons = {
            Gun = {
                Unlocked = true,
                ...
            },
            Sword = {
                Unlocked = false,
                ...
            }
    },
    ...
}
2 Likes