I’ve been trying to make a datastore and everything in the code seems to be correct, however I can’t save any arrays, tables, or dictionaries. I have already searched the forum and gotten the same answer time and time again. the same exact answer already implemented into my code. I have API services on, and I am genuinely stumped on what the problem could possibly be.
This script returns this error:
DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. API: SetAsync
local players = game:GetService("Players")
local datastoreService = game:GetService("DataStoreService")
local datastore = datastoreService:GetDataStore("PlayerData")
local repStorage = game:GetService("ReplicatedStorage")
local killers = repStorage:WaitForChild("Killers")
local survivors = repStorage:WaitForChild("Survivors")
players.PlayerAdded:Connect(function(plr)
local selectedKiller = Instance.new("ObjectValue", plr)
selectedKiller.Name = "Killer"
selectedKiller.Value = killers.Copy
local killerSkin = Instance.new("ObjectValue", plr)
killerSkin.Name = "KillerSkin"
--killerSkin.Value = skins.Killer.Copy.Brickbattler
local selectedSurvivor = Instance.new("ObjectValue", plr)
selectedSurvivor.Name = "Survivor"
selectedSurvivor.Value = survivors.Jack
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Name = "Money"
local corruption = Instance.new("NumberValue", leaderstats)
corruption.Name = "Corruption"
local inRound = Instance.new("BoolValue", plr)
inRound.Name = "InRound"
local data
local success, err = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
if success and data then
money.Value = data[1]
selectedKiller.Value = data[2]
selectedSurvivor.Value = data[3]
else
print("Player: " .. plr.Name .. " has no data.")
end
end)
local function saveData(plr:Player)
local dataToSave = {
["Money"] = plr.leaderstats.Money.Value,
["Killer"] = plr.Killer.Value,
["Survivor"] = plr.Survivor.Value
}
local success, err = pcall(function()
datastore:SetAsync(plr.UserId, dataToSave)
end)
if success then
print("Data Saved, " .. plr.Name)
else
print("Data Not Saved, " .. plr.Name .. ", Error code " .. err)
end
end
players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
game:BindToClose(function()
for _, plr in pairs(players:GetPlayers()) do
saveData(plr)
end
end)