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

"Cannot store Array in data store. Data stores can only accept valid UTF-8 characters." How to fix?

Asked by 5 years ago
Edited 5 years ago

Uh hello, Also I tried to do a Value saving script also it saves multiple and I became this error: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters. How could I fix this?

Script: l

ocal DS = game:GetService("DataStoreService")

local PetDS = DS:GetDataStore("PetDataStore")

local PetsTable = {}

local AUTOSAVE_INTERVAL = 60



game.Players.PlayerAdded:Connect(function(Player)

local PetsFolder = Instance.new("Folder")

PetsFolder.Name = "Pets"

PetsFolder.Parent = Player

local key = Player.UserId

PetsTable = PetDS:GetAsync()

if PetsTable then

for _,p in pairs (PetsTable) do

local In = Instance.new("IntValue")

In.Name = p["Name"]

In.Parent = PetsFolder

In.Value = p["Value"]

end

end

end)



game.Players.PlayerRemoving:Connect(function(Player)

for _,p in pairs (PetsTable) do

table.remove(PetsTable,p)

end

for _,i in pairs (Player.Pets:GetChildren()) do

if i then

table.insert(PetsTable,i)

PetsTable[i] = {}

table.insert(PetsTable[i],"Name")

table.insert(PetsTable[i], "Value")

PetsTable[i]["Name"] = i.Name

PetsTable[i]["Value"] = i.Value

print(PetsTable[i]["Name"])

PetDS:SetAsync(Player.UserId, PetsTable)

end

end

end)

Would be great!

0
call SetAsync outside after the loop hellmatic 1523 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Since arrays aren't allowed in datastores, you can get around this by encoding them.

-- Change line 69

PetDS:SetAsync(Player.UserId, PetsTable) -- Not allowed 
PetDS:SetAsync(Player.UserId,game:GetService("HttpService"):JSONEncode(PetsTable)) -- Allowed

This will turn your array into a string, allowing it to be used in datastores.

Ad

Answer this question