Datastore Help - error 104

Hiya guys.
im not exactly a wizz with datastores so ima give it to ya.

 DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. API: SetAsync, Data Store: TestData7 

got this error.

heres my code. i feel like ive doing this very clearly wrong but, idk how else to do it.


local Players = game:GetService("Players")
local DatastoreService = game:GetService("DataStoreService")
local database = DatastoreService:GetDataStore("TestData7")
local sessionData = {}


local Races = {
	{"Race1", 40},
	{"Race2", 40},
	{"Race3", 40},
	{"Race4", 40},
	{"Race5", 40},

}


local multiplier = 1

for _, item in pairs(Races) do --Essentially edits the multiplier so that even the smallest decimal will become whole
	local function zeros(amount)
		local total = "1"
		for i = 1, amount do
			total = total.. "0"
		end
		return total
	end
	local split = string.split(tostring(item[2]), ".")
	if split[2] ~= nil then
		if tonumber(zeros(string.len(split[2]))) > multiplier then
			multiplier = tonumber(zeros(string.len(split[2])))
		end
	end
end
print(multiplier)
for _, item in pairs(Races) do
	item[2] = item[2] * multiplier
end

local TotalWeight = 0

for _,ItemData in pairs(Races) do
	TotalWeight = TotalWeight + ItemData[2]
end

local function chooseRandomItem()
	local Chance = math.random(1,TotalWeight)
	local Counter = 0
	for _,ItemData in pairs(Races) do
		Counter = Counter + ItemData[2]
		if Chance <= Counter then
			return ItemData[1]
		end
	end
end







--Functions
--playeradded
function PlayerIsAdded(player)



	print(player.Name,"has joined the server.")


	local PlayerStats = Instance.new("Folder")
	PlayerStats.Name = "PlayerStats"

	local Skills  =  Instance.new("StringValue")
	Skills.Name = "Skills" --rebirth
	Skills.Parent = PlayerStats
	
	local Race  =  Instance.new("StringValue")
	Race.Name = "Race" --rebirth
	Race.Parent = PlayerStats
	
	local SkillFolder  =  Instance.new("Folder")
	SkillFolder.Name = "SkillFolder" --rebirth
	SkillFolder.Parent = PlayerStats
	
	local Injuries  =  Instance.new("StringValue")
	Injuries.Name = "Injuries" --rebirth
	Injuries.Parent = PlayerStats
	
	local Inventory=  Instance.new("StringValue")
	Inventory.Name = "Inventory" --rebirth
	Inventory.Parent = PlayerStats
	
	local Class = Instance.new("StringValue")
	Class.Name = "Class" --rebirth
	Class.Parent = PlayerStats

	local ManaColor = Instance.new("Color3Value")
	ManaColor.Name = "ManaColor" --rebirth
	ManaColor.Parent = PlayerStats
	
	local Face = Instance.new("StringValue")
	Face.Name = "Face" --rebirth
	Face.Parent = PlayerStats


	local Armour = Instance.new("StringValue")
	Armour.Name = "Armour" --rebirth
	Armour.Parent = PlayerStats

	local CharacterName = Instance.new("StringValue")
	CharacterName.Name = "CharacterName" --rebirth
	CharacterName.Parent = PlayerStats

	local Enchant = Instance.new("StringValue")
	Enchant.Name = "Enchant" --rebirth
	Enchant.Parent = PlayerStats
	
	local Weapon = Instance.new("StringValue")
	Weapon.Name = "Weapon" --rebirth
	Weapon.Parent = PlayerStats
	
	local Alignment = Instance.new("IntValue")
	Alignment.Name = "Alignment" --rebirth
	Alignment.Parent = PlayerStats
	
	local Grips = Instance.new("IntValue")
	Grips.Name = "Grips" --rebirth
	Grips.Parent = PlayerStats
	
	local Silver = Instance.new("IntValue")
	Silver.Name = "Silver" --rebirth
	Silver.Parent = PlayerStats
	
	local IsMaxed = Instance.new("BoolValue")
	IsMaxed.Name = "IsMaxed" --rebirth
	IsMaxed.Parent = PlayerStats
	


	local IsVampire = Instance.new("BoolValue")
	IsVampire.Name = "IsVampire" --rebirth
	IsVampire.Parent = PlayerStats
	
	

	
	

	local success = nil
	local PlayerData = nil
	local attempt = 1

	repeat
		success, PlayerData = pcall(function()
			return database:GetAsync(player.UserId)
		end)
		attempt +=1
		if not success then
			warn(PlayerData)
			task.wait(3)
		end
	until success or attempt == 5

	if success then
		print("Connected to database")
		
		
		
		if not PlayerData then
			print("Assigning default data")
			
		
			
			
			PlayerData = {
				["Skills"] = "",
				["Injuries"] = "",
				["Inventory"] = "",
				["Weapon"] = "Fists",
				["Class"] = "None",
				["Alignment"] = 0,
				["Grips"] = 0,
				["IsMaxed"] = false,
				["IsVampire"] = false,
				["Enchant"] = "None",
				["Armour"] = "Rags",
				["Race"] = tostring(chooseRandomItem()) ,
				["Face"] = "",
				["Silver"] = 100,
				["ManaColor"] = Color3.new(math.random(), math.random(), math.random()),





			}
		end
		sessionData[player.UserId] = PlayerData
	else
		warn("Unable to get data for",player.UserId)
		player:Kick("Unable to load data. Try again later.")
	end



	Skills.Value = sessionData[player.UserId].Skills
	Skills.Changed:Connect(function()
		sessionData[player.UserId].Skills = Skills.Value
	end)
	
	Injuries.Value = sessionData[player.UserId].Injuries
	Injuries.Changed:Connect(function()
		sessionData[player.UserId].Injuries = Injuries.Value
	end)

	Inventory.Value = sessionData[player.UserId].Inventory
	Inventory.Changed:Connect(function()
		sessionData[player.UserId].Inventory = Inventory.Value
	end)
	
	Silver.Value = sessionData[player.UserId].Silver
	Silver.Changed:Connect(function()
		sessionData[player.UserId].Silver = Silver.Value
	end)
	
	Weapon.Value = sessionData[player.UserId].Weapon
	Weapon.Changed:Connect(function()
		sessionData[player.UserId].Weapon = Weapon.Value
	end)
	
	ManaColor.Value = sessionData[player.UserId].ManaColor
	ManaColor.Changed:Connect(function()
		sessionData[player.UserId].ManaColor = ManaColor.Value
	end)
	
	Class.Value = sessionData[player.UserId].Class
	Class.Changed:Connect(function()
		sessionData[player.UserId].Class = Class.Value
	end)
	
	Alignment.Value = sessionData[player.UserId].Alignment
	Alignment.Changed:Connect(function()
		sessionData[player.UserId].Alignment = Alignment.Value
	end)

	Grips.Value = sessionData[player.UserId].Grips
	Grips.Changed:Connect(function()
		sessionData[player.UserId].Grips = Grips.Value
	end)

	IsMaxed.Value = sessionData[player.UserId].IsMaxed
	IsMaxed.Changed:Connect(function()
		sessionData[player.UserId].IsMaxed = IsMaxed.Value
	end)

	IsVampire.Value = sessionData[player.UserId].IsVampire
	IsVampire.Changed:Connect(function()
		sessionData[player.UserId].IsVampire = IsVampire.Value
	end)


	Race.Value = sessionData[player.UserId].Race
	Race.Changed:Connect(function()
		sessionData[player.UserId].Race = Race.Value
	end)


	Armour.Value = sessionData[player.UserId].Armour
	Armour.Changed:Connect(function()
		sessionData[player.UserId].Armour = Armour.Value
	end)


	Enchant.Value = sessionData[player.UserId].Enchant
	Enchant.Changed:Connect(function()
		sessionData[player.UserId].Enchant = Enchant.Value
	end)


	
	Face.Value = sessionData[player.UserId].Face
	Face.Changed:Connect(function()
		sessionData[player.UserId].Face = Face.Value
	end)

	PlayerStats.Parent = player


end
--player leaving
function PlayerLeaving(player)
	print(player.Name,"has left the server.")
	if sessionData[player.UserId] then
		local success = nil
		local errorMsg = nil
		local attempt = 1


		repeat
			success, errorMsg = pcall(function()
				database:SetAsync(player.UserId, sessionData[player.UserId])
		
			end)
			attempt +=1
			if not success then
				warn(errorMsg)
				task.wait(3)
			end
		until success or attempt == 5

		if success then
			print("Data saved for", player.Name)
		else
			warn("Unable to save data for",player.Name)
		end

	end
end


game:BindToClose(function()
	task.wait(1)
end)

Players.PlayerAdded:Connect(PlayerIsAdded)
Players.PlayerRemoving:Connect(PlayerLeaving)


From what I can tell, it looks like you’re trying to save instances to the store. You can’t save instances. You could save names or something the data can be identified by.

You can save dictionaries that contain:

  • strings
  • numbers
  • Booleans

so would it be the color3 values that its disagreeing fun with?

Not sure, if that’s the instances you’re trying to save, then yes. You could save each individual part of the Color3.

local Colour = --path here

local saveData = {
    ["Colour"] = {Colour.R, Colour.G, Colour.B}
}

--then, to load:
local colour = Color3.new(table.unpack(saveData.Colour))

I recommend hex strings for Color storing, they have a broader range.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.