Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 ?

3 comments

0

Any Senpais that can handle this tricky question?

0

Let's see... Brain explodes

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!

1 answer

✓ Accepted answer

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

--This belongs in a server script
local toolsfolder  = game.ServerStorage.Tools
local  DataStore = game:GetService("DataStoreService"):GetDataStore("InventorySaves")

function arbitraryfunction(player,type)
    if type  == "Load" then  --Loads the tools
        local savedtools = DataStore:GetAsync("user_"..player.UserId) --grabs the async
		if savedtools then
			print("Loaded")
        for _,toolname in next, savedtools do --Loops through the async for the tools
			print(toolname)
            if toolsfolder:FindFirstChild(toolname) then --Checks if the tool is in the toolsfolder
            toolsfolder[toolname]:Clone().Parent = player.StarterGear;toolsfolder[toolname]:Clone().Parent = player.Backpack --Clones it into the player's SG and BP
            end
        end
		end
    elseif type == "Save" then  --Saves the tools
		print("Saved")
        local toolstosave = {}
        for _,tool in pairs(player.Backpack:GetChildren()) do
		table.insert(toolstosave,tool.Name)
        end
        DataStore:SetAsync("user_"..player.UserId, toolstosave) --Updates the async
    end 
end 
game.Players.PlayerAdded:connect(function(Player)
arbitraryfunction(Player,"Load")
Player.Chatted:connect(function(msg)
	if msg:lower() == ("Save"):lower() then
		arbitraryfunction(Player,"Save")
	end
end)
end)


This discussion is preserved as it was. New answers, comments, and votes are closed.