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

How do I save multiple things in a OrderedDataStore?

Asked by
DollorLua 235 Moderation Voter
4 years ago

So I have been trying to get this ordered datastore to save 3 different player datas. I have tried saving them separately, but I get the orange error that says theres too many inputs for the key. It said it didn't allow Dictionaries either. Then a JSON encoded it but it doesn't accept strings. I need help. I Know that Ordered datastores only accept numbers. Heres the code:

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetOrderedDataStore('plrData')

game.Players.PlayerAdded:Connect(function(plr)
    local data
    local key = plr.Name
    pcall(function()
        data = DS:GetAsync(key)
    end)
    local folder = Instance.new("Folder")
    folder.Parent = plr
    folder.Name = 'leaderstats'
    local Steps = Instance.new("IntValue")
    Steps.Parent = folder
    Steps.Name = 'Steps'
    local Total = Instance.new("IntValue")
    Total.Parent = folder
    Total.Name = 'TotalSteps'
    local Wins = Instance.new("IntValue")
    Wins.Parent = folder
    Wins.Name = 'RaceWins'
    if data then
        Steps.Value = data.idk['Steps']
        Total.Value = data.idk['Total']
        Wins.Value = data.idk['Wins']
    else
        Steps.Value = 0
        Total.Value = 0
        Wins.Value = 0
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local key = plr.Name
    local idk = {}
    idk['Steps'] = plr.leaderstats.Steps.Value
    idk['Total'] = plr.leaderstats.TotalSteps.Value
    idk['Wins'] = plr.leaderstats.RaceWins.Value
    DS:SetAsync(key, idk)
end)

reminder: no rude or toxic stuff about the simulator part.

1 answer

Log in to vote
5
Answered by
megukoo 877 Moderation Voter
4 years ago

Sorry, but OrderedDataStores are used for saving an integer to a key. They cannot be used with other values.. etc.

If you want to sort singular stats like wins or points, save the individual values to different OrderedDataStores.

0
I know im late and thank you for taking time to answer. I always leave this sight for a while but ill try to stay on it this time. I accept this thank you. DollorLua 235 — 4y
Ad

Answer this question