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

Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters?

Asked by 4 years ago

I was trying to save data for a minigame and I get an error. Can anyone fix it? Thanks.

local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("MinigamePoints")
game.Players.PlayerAdded:Connect(function(plr)
    local coins = Instance.new("IntValue",plr)
    coins.Name = "Coins"
    local key = "id-"..plr.UserId
    local savedcoins = experienceStore:GetAsync(key)
    if savedcoins then
        coins = savedcoins[1]
    else
        local coinssaving = {coins.Value}
        experienceStore:SetAsync(key,coins)
    end
end)
game.Players.PlayerRemoving:Connect(function(plr)
    local key = "id-"..plr.UserId
    local save = {plr.Coins.Value}
    experienceStore:SetAsync(key,save)
end)
0
In DataStores you can save only player information, you can not save instances per se, you need to save the value of the instance. Usually people create tables in which they store all the necessary information of a player or save the "value" of the IntValue for example, not the instance itself. iDarkGames 483 — 4y
0
line 17 {tostring(plr.Coins.Value)} (also reset your datastore) line 11 coinssaving = {tostring(coins.Value)} First reset your datastore to see if it fixed it. greatneil80 2647 — 4y

Answer this question