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

Bem… Eu refiz um module script que ia fazer uma “metatable” para quando um jogador entrasse no jogo, ele ia adcionar o nome do jogador a esta metatable ou table mesmo e tambem iria colocar uma outra table que contia os stats de um jogador dentro da nova table que seria a do player que entrasse no jogo:

The module script:

function players.addPlayer(name)
	
	players[name] = status
	print(players)
	
end

And I also made a script that saves the player’s data:

local badge = game:GetService("BadgeService")
local clans = require(game.ReplicatedStorage.Clans)
local plrData = require(game.ReplicatedStorage.plrData)

local dataStore = game:GetService("DataStoreService")
local dataGroup = dataStore:GetDataStore("PlayerStats")
local events = game.ReplicatedStorage:WaitForChild("Events")

local alrJoined = false
game.Players.PlayerAdded:Connect(function(player)

	local key = player.UserId

 if alrJoined == true then
		
   dataGroup:GetAsync(key)
   print("Loaded!")
 end
 
 if alrJoined == false then

   plrData.addPlayer(player.Name)
   plrData.SetClanAndNenCategory(player.Name)
   plrData.Contruct(player.Name)
   
   ----------
   ----------
   local plrInfoTxt = player.PlayerGui:WaitForChild("PlayerBar"):WaitForChild("PlayerInfo")
   plrInfoTxt.Text = "(WIP) ,"..plrData[player.Name].Clan.."(WIP)"..", Potential: "..plrData[player.Name].Potential
   
   ----------
   ----------
   local char = player.Character or player.Character:Wait()
   
   local hum = char:WaitForChild("Humanoid")
   hum.WalkSpeed = plrData[player.Name].Speed
   hum.MaxHealth = plrData[player.Name].Defense
   hum.Health = plrData[player.Name].Defense
	
   ----------
   ----------
   local sucess,failed = pcall(function()
 
   dataGroup:SetAsync(key,plrData[player.Name])
   print("Saved!")
   end)
   
   if not sucess then
		
		warn("Error!")
   end
   
 end


end)

The problem is that whenever I load or exit the game a message appears saying:

I also looked and found several people with the same error as mine but with very different codes…

I hope for answers! :grin:

4 Likes

What is status in the ModuleScript? DataStores can only store certain values

Why are you loading and storing player data with a variable underneath PlayerAdded?

1 Like

Does the variable you are talking about refer to local key = plr.UserId?

1 Like

This one ^

the statuses I’m talking about is a table that contains numbers and strings only:

local status = {
	
	NenCategory = "None",
	Name = "None",
	Defense = 100,
	Age = 0,
	Clan = "None",
	Speed = 28,
	Strenght = 2,
	Potential = 0,
	Level = 1,
	Hatsu = "None",
	Nen = 0,
	Ten = 0,
	Ren = 0,
	Zetsu = 0,
	Ko = 0,
	Gyo = 0,
	In = 0,
	En = 0,
	Shu = 0,
}

This variable serves to identify whether the player has ever entered the game or not

1 Like

The data seems fine, can I see how the SetClanAndNenCategory and Construct methods interact with the data? They may be inserting invalid values

Doesn't relate to the error, but other stuff I noted

Since you’re setting it to the status table (which I’m assuming isn’t copied), everyone will have the same status table as their value:

-- example
local t1 = {k = 2, i = 3}
local t2 = t1

t2.k = 3
print(t1.k) --> prints '3' instead of '2'

You should do:

players[name] = table.clone(status)

You can just do GetAsync and check if the player’s data is nil to check if the player played the game before; the variable won’t do much because it will be set to false (by default) for every new server that is created. Also, since this is server sided, if the variable is ever set to true, it will be set to true for everyone else who also joins.

But the variable is never changed in the code? So that’s why I was confused

1 Like
function players.Contruct(name)
	
	players[name].Potential = math.random(1,100)
	players[name].Speed = players[name].Speed + (players[name].Potential/15)
	players[name].Strenght = players[name].Strenght + (players[name].Potential/10)
	players[name].Defense = players[name].Defense + (players[name].Potential/1)
	print(name..":"..players[name].Potential ," ",players[name].Speed ," ",players[name].Strenght," ",players[name].Defense)
end

function players.SetClanAndNenCategory(name)
	
  local nenType = {
		
		Enhancer = 60,
		Emission = 60,
		Transmutation = 60,
		Manipulation = 60,
		Conjuration = 60,
		Specialist = 1,
  }
	local sum1 = 0
	
	for _,values in pairs(nenType) do
		
		sum1 = sum1 + values
	end
	
	local function nenCategory()
		
		local clanV = Random.new():NextNumber(0,sum1)
		
		for i,v in pairs(nenType) do
			
			 clanV = clanV - v
		
		if clanV < 0 then
			
			return i
		end
			
		end
	end
	
	players[name].NenCategory = nenCategory()
	print("Your name type is"..players[name].NenCategory.."!")
	
	local cc = {

		Zoldyck = 1,
		Kurta = 0.1,
		Kreuger = 5,
		Netero = 1,
		Freecs = 1,
		Todoroki = 0.5,
		Hatake = 60,
		Takano = 60,
		Tsezguerra = 60,
		Portor = 60,
		Kimito = 60,
		Sugerawa = 60,
		Uchiha = 0.001,

	}
	
	local sum2 = 0

	for _,values in pairs(cc) do

		sum2 = sum2 + values
	end

	local function setClan()

		local clanV = Random.new():NextNumber(0,sum2)

		for i,v in pairs(cc) do

			clanV = clanV - v

			if clanV < 0 then

				return i
			end

		end
	end
	
	players[name].Clan = setClan()
	print("Your clan is "..players[name].Clan.."!")
	
	if players[name].Clan == "Zoldyck" then


	elseif players[name].Clan == "Kurta" then


	elseif players[name].Clan == "Kreuger" then


	elseif players[name].Clan == "Netero" then


	elseif players[name].Clan == "Freecs" then

	end
	
end

In the case of statuses, I hadn’t thought about that since for me the table would be cloned automatically

it sounds like you’re storing characters that aren’t allowed in a datastore. they only accept UTF-8 characters, which is a specific set of chars - are you doing something with Unicode?

as a side note, you’re literally doing nothing with the data you get, not even setting it to a variable or anything. have you not included something in the script? also i would use RemoteEvents for the changing of a PlayerGui, it’s not great practise to just modify the GUI from the server

1 Like

You can, I do it in my own game

Absolutely wrong. You also don’t need to JSON encode/decode since DataStores already do that for you.

@OP, print out exactly what the data is just before it is saved. You might be saving a non-saveable type or a bad string.

1 Like

…i have no idea where that absolute lie came from. i literally wrote code to store a table in a datastore yesterday as part of my summer event system

image

apologies, i haven’t had much sleep lately. maybe i was thinking of a web server? honestly i don’t even know at this point

edit: maybe i was thinking about how they’re converted at the method level to a string, idk

well what I put to save was a simple table with some variables that contain string and numbers only…

maybe try printing what you’re about to store so we can see if there’s anything wrong with encoding or formatting?

Print  pro Dev forum dictionary data store

Is that what was supposed to be printed?

Yes, I’m really lost as to what could be causing the issue here.

I can only guess, that perhaps it’s because of the speed floating point:

image

Try rounding it down to just 30 (use math.floor), and see what happens. If that still doesn’t work, I’m at a lost

Is this what is being outputted from plrData[player.Name]? And is this directly before you call SetAsync?

1 Like

Solved guys, it was just a code that I had forgotten to delete, but thank you for helping me!

1 Like