Saving multiple StringValues to one datastore

How would I go about saving around 7 StringValues to one datastore? I have a datastore script set up for individual values, but I want to save and load multiple from 1 datastore, but I don’t know how.

Here’s my script: (datastores have been changed to avoid accessing them)

local datastoreService = game:GetService("DataStoreService")
local SpeciesData = datastoreService:GetDataStore("stet")
local WonderAmountData = datastoreService:GetDataStore("stetet")
local WondersData = datastoreService:GetDataStore("stetert")
local BloodlineData = datastoreService:GetDataStore("strte")
local s
local wa
local w
local b

game.Players.PlayerAdded:Connect(function(player)
	local bloodline = Instance.new("StringValue", player)
	bloodline.Name = "Bloodline"
	bloodline.Value = BloodlineData:GetAsync(player.UserId) or nil
	if bloodline.Value ~= nil then
		b = true
	else
		b = false
	end
	local wonderamount = Instance.new("StringValue", player)
	wonderamount.Name = "WonderAmount"
	wonderamount.Value = WonderAmountData:GetAsync(player.UserId) or nil
	if wonderamount.Value ~= nil then
		wa = true
	else
		wa = false
	end
	local species = Instance.new("StringValue", player)
	species.Name = "Species"
	species.Value = SpeciesData:GetAsync(player.UserId) or nil
	if species.Value ~= nil then
		s = true
	else
		s = false
	end
	-- i want to save multiple string values to the Wonders datatstore here
end)

Just put all the strings into a table and save that.

1 Like

how would i load them as individual stringvalues though?

1 Like

Input table:

:SetAsync(key, 
    {
        string1 = "",
        string2 = "",
        string3 = "",
        string4 = "",
        string5 = "",
        string6 = "",
        string7 = "",
    })

And to retrieve your data:

local data = :GetAsync(key)
local string1, string2, ... = data.string1, data.string2, ...
1 Like