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

Why is my DataStore getting an error? and How can I fix it?

Asked by
sad_eyez 162
6 years ago

If anyone could give me some help that'd be great, I haven't scripted in awhile and I forgot a few things about datastores, please help if you can.

Error:

07:41:37.793 - 104: Cannot store Dictionary in DataStore 07:41:37.794 - Stack Begin 07:41:37.794 - Script 'ServerScriptService.DataStore', Line 44 07:41:37.795 - Stack End

Code:

local dataService = game:GetService("DataStoreService"):GetDataStore("Alpha #1")

game.Players.PlayerAdded:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:wait()

    local stats = Instance.new("Folder", plr)
    stats.Name = "Stats"

    local money = Instance.new("NumberValue", stats)
    money.Name = "Money"
    money.Value = 500

    local subscribers = Instance.new("NumberValue", stats)
    subscribers.Name = "Subscribers"

    local channel = Instance.new("StringValue", stats)
    channel.Name = "Channel"

    local characterCreated = Instance.new("BoolValue", stats)
    characterCreated.Name = "characterCreated"
    characterCreated.Value = false

    local hair = Instance.new("StringValue", stats)
    hair.Name = "Hair"
    local hairColor = Instance.new("Color3Value", stats)
    hairColor.Name = "HairColor"

    local shirt = Instance.new("StringValue", stats)
    shirt.Name = "Shirt"

    local pants = Instance.new("StringValue", stats)
    pants.Name = "Pants"



    local playerKey = plr.UserId .. "-key"
    local savedValues = dataService:GetAsync(playerKey)

    if not savedValues then
        local valuesToSave = {}
        for i,v in pairs(stats:GetChildren()) do
            valuesToSave[tostring(v.Name)] = v.Value
        end
        dataService:SetAsync(playerKey, valuesToSave)
        print("Successfully Saved Data!")
    else
        for i,v in pairs(savedValues) do
            stats[tostring(i)].Value = v
        end
        print("Successfully Loaded Data!")
    end


end)

game.Players.PlayerRemoving:Connect(function(plr)
    local playerKey = plr.UserId .. "-key"
    local valuesToSave = {}
    for i,v in pairs(plr.Stats:GetChildren()) do
        valuesToSave[tostring(v.Name)] = v.Value
    end
    dataService:SetAsync(playerKey, valuesToSave)
    print("Successfully Saved Data!")
end)

0
can you friend me in roblox so you can help me with datastore? Thats the only skill i need to learn before i can truely declare my self a master User#20192 0 — 6y
0
If you don't even know datastore you're far away from a master dude,datastore is the most important thing in scripting User#20388 0 — 6y
0
I think you just have to use table.insert instead of usingvaluesToSave[tostring(v.Name)] = v.Value User#20388 0 — 6y
0
I figured it out, I didn't know you couldn't save a Color3Value sad_eyez 162 — 6y

Answer this question