Ad
Log in to vote
0

Dictionary is not allowed in DataStore??

Asked by
NotPix 2
7 months ago
Edited 7 months ago

What do I need to add to remove this error? Seems to break at the DS:GetAsync

Pieces of the main script posted below; bare with me i'm new to this..

local DS = game:getService("DataStoreService"):GetOrderedDataStore("Stats")


game.Players.PlayerAdded:connect(function(player)
    local Data = script.Data:Clone()
    Data.Parent = player
    local CopyData = script.Data.leaderstats:Clone()
    CopyData.Parent = player
    --stat() 
    if DS then
        local Stats = DS:GetAsync(player.userId);-- find old save
        if Stats then
            for _,Type in next,Data:GetChildren()do
                for _,S in next,Type:GetChildren()do
                    if Stats[S.Name]then
                        S.Value = Stats[S.Name]
                    end
                end
            end
        end
    end

    player.CharacterAdded:connect(function(char)    
    if char:WaitForChild("Humanoid") then
        update()    
        Insert_FallDmg(char); -- Enables Damage_On_Fall
        Insert_Ragdoll(char); -- Enables Death_Animation
        Insert_Blood(char);
        Insert_Sprint(char);
        wait(1) 
        Change_Clothes(char);
        CheckBadges(player)
        if isAuthenticated(player) then
        print(player.Name .. " has bought the game pass with id " .. passId)
        game.ReplicatedStorage.Weapons.M1014:Clone().Parent = player.Backpack
        player.Data.Inventory.M1014.Value = 1
        char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 50
        char.Humanoid.Health = char.Humanoid.Health + 50
        end
    end
    end)    
end)

game.Players.PlayerRemoving:connect(function(player)
    local Data = player:FindFirstChild("Data")
    local Stats = {}
    if Data then
        for _,Type in next,Data:GetChildren()do
            for _,S in next,Type:GetChildren()do
                Stats[S.Name] = S.Value
            end
        end
    end
    if DS then
        DS:SetAsync(player.userId,Stats)
    end
end)

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by
BlackJPI 2525 Snack Break
7 months ago

This problem is that you are using an Ordered Data Store. An ODS is like a regular old Data Store, except that it sorts data in either ascending or descending order. Because of this, the only type of object you are allowed to store as values are integers. This becomes very useful for creating leaderboards across servers and other implementations where efficiently ordering data is very important.

In your case, I don't see why you would want to use an ODS. For saving player data, a regular Data Store should suffice.

local DS = game:GetService("DataStoreService"):GetDataStore("Stats")
Ad

Answer this question



Ad