Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

What is the best way to save a lot of values with DataStore?

Asked by
deris88 146
8 years ago

I'm having trouble with this. I made shop that has a lot of items. I gave each item an ID code. Every time player buys the item, ID code must be saved. So what is best way to save all them?

I mean there is Saving limit in Data stores and I will be adding a lot of items. Won't I reach the limit of saves? Is there a better way to save all of the ID's without creating an IntValue for each ID to save ?

0
Any Senpais that can handle this tricky question? deris88 146 — 8y
0
Let's see... *Brain explodes* NathanAdhitya 124 — 8y
0
Despite the fact it might be quite a bit more difficult, you could try hosting a SQL database on a free website and having your game contact your website to save items. I highly doubt you will run out of space in your database! voximity 75 — 8y

1 answer

Log in to vote
1
Answered by
systack 123
8 years ago

The power of arrays!

Let's assume I have a place in serverstorage that contains all the tools in the game, and I want it so when players say "Save" it saves the game. It'd look something like this

01--This belongs in a server script
02local toolsfolder  = game.ServerStorage.Tools
03local  DataStore = game:GetService("DataStoreService"):GetDataStore("InventorySaves")
04 
05function arbitraryfunction(player,type)
06    if type  == "Load" then  --Loads the tools
07        local savedtools = DataStore:GetAsync("user_"..player.UserId) --grabs the async
08        if savedtools then
09            print("Loaded")
10        for _,toolname in next, savedtools do --Loops through the async for the tools
11            print(toolname)
12            if toolsfolder:FindFirstChild(toolname) then --Checks if the tool is in the toolsfolder
13            toolsfolder[toolname]:Clone().Parent = player.StarterGear;toolsfolder[toolname]:Clone().Parent = player.Backpack --Clones it into the player's SG and BP
14            end
15        end
View all 33 lines...
Ad

Answer this question