I want to make a game where you collect 64 keys in order to unlock the gate of the mines. The issue is that I don’t know how Im supposed to go about saving how many keys a player has, and deleting the keys that they already got in the game to make sure that they won’t get over 64 key.
Generally the way you format data should be as table so create a dictionary in the table regarding which keys have been collected. For each collected key, create an index of the key name with just a boolean value of true therefore if the keyname is nil then they haven’t collected it, else they have.
If they are unique keys (as opposed to randomly generated) you can save them in an array by a unique identifier like if you set the name to be different for each one you could use that.
local collectedkeys: {string} = {}
-- check if collected
local already_found = table.find(collectedKeys, key.Name) ~= nil
-- collecting a new key
if not already_found then
table.insert(collectedKeys, key.Name)
end
-- counting keys
local key_count = #collectedKeys
make sure to run some of these examples on the server to reduce client side hackers
Basic Usage - ProfileService If you are more comfortable using normal datastores there’s no problem with using that. SetAsync("Keys", collectedKeys) saving on collection shouldn’t give as many problems as other save-on-close solutions posted here like in the community tutorials pages “Datastores - Beginners to Advanced”