Save code rewards?

I know about the save leaderstats type but how do I save one for a code that gives an ITEM like some sword or skin? Do I use values?

Help would be appreciated!

When saving things like Player Items or things like that, you should know that DataStore itself doesn’t actually store items. It can’t contain those tangible items. So instead, what you should look at it as Values or strings!

  • Use the DataStore to save Items as a string, preferably in a table! And when the player joins the game, just iterate through that DataStore and give the corresponding item to the player.

This could also work if you give your items serial values. And saving items as a table in a DataStore works the same as saving anything else!

dataStore:SetAsync(key, {list of items})
# or
dataStore:SetAsync(key, items)

And when retrieving it, if your table is a simple list it should come out as such:

dataStore:GetAsync(key) 
# Which would appear as...
[Key] = {items}

So you could use a simple i,v in pairs loop to iterate through the save!

2 Likes

hard to understand but I think I got the main point…

or do I

In short saving all the items in a list. Like this :

SavedItems = {"Sword", "Gun", "Hat"}
dataStore:SetAsync(key, SavedItems)

And retrieving the items would look like this:

data = dataStore:GetAsync(key)
for i,v in pairs(data)do
     item = itemFolder:FindFirstChild(v):Clone()
     item.Parent = playerBackPack
end

Of course if you have different type of items, you’d have to sort through that.

1 Like

Okay, that is way easier to understand. Thanks!

1 Like