Why do I get the error "Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters."

Yesterday night I was scripting and I didn’t have this error. Today I’m scripting and I receive an error in the title. It worked yesterday night but today it doesn’t save my values anymore.

local DS = game:GetService("DataStoreService")
local Inventory = DS:GetDataStore("FirstInventory")

game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Parent = player
	Folder.Name = "Inventory"
	
	local Folder = Instance.new("Folder")
	Folder.Parent = player.Inventory
	Folder.Name = "Seeds"
	
	local Folder = Instance.new("Folder")
	Folder.Parent = player.Inventory
	Folder.Name = "Plants"
	
	local Folder = Instance.new("Folder")
	Folder.Parent = player.Inventory
	Folder.Name = "Furniture"
	
	local WheatSeed = Instance.new("IntValue")
	WheatSeed.Name = "Wheat"
	WheatSeed.Parent = player.Inventory.Seeds
	
	local StrawberrySeed = Instance.new("IntValue")
	StrawberrySeed.Name = "Strawberry"
	StrawberrySeed.Parent = player.Inventory.Seeds
	
	local CarrotSeed = Instance.new("IntValue")
	CarrotSeed.Name = "Carrot"
	CarrotSeed.Parent = player.Inventory.Seeds
	
	local WatermelonSeed = Instance.new("IntValue")
	WatermelonSeed.Name = "Watermelon"
	WatermelonSeed.Parent = player.Inventory.Seeds
	
	local PotatoSeed = Instance.new("IntValue")
	PotatoSeed.Name = "Potato"
	PotatoSeed.Parent = player.Inventory.Seeds
	
	local CoconutSeed = Instance.new("IntValue")
	CoconutSeed.Name = "Coconut"
	CoconutSeed.Parent = player.Inventory.Seeds
	
	local BananaSeed = Instance.new("IntValue")
	BananaSeed.Name = "Banana"
	BananaSeed.Parent = player.Inventory.Seeds
	
	local PineappleSeed = Instance.new("IntValue")
	PineappleSeed.Name = "Pineapple"
	PineappleSeed.Parent = player.Inventory.Seeds
	
	local CabbageSeed = Instance.new("IntValue")
	CabbageSeed.Name = "Cabbage"
	CabbageSeed.Parent = player.Inventory.Seeds
	
	local TomatoSeed =  Instance.new("IntValue")
	TomatoSeed.Name = "Tomato"
	TomatoSeed.Parent = player.Inventory.Seeds
	
	local WheatPlant = Instance.new("IntValue")
	WheatPlant.Name = "WheatPlant"
	WheatPlant.Parent = player.Inventory.Plants
	
	local CarrotPlant = Instance.new("IntValue")
	CarrotPlant.Name = "CarrotPlant"
	CarrotPlant.Parent = player.Inventory.Plants
	
	local PotatoPlant = Instance.new("IntValue")
	PotatoPlant.Name = "PotatoPlant"
	PotatoPlant.Parent = player.Inventory.Plants
	
	local CabbagePlant = Instance.new("IntValue")
	CabbagePlant.Name = "CabbagePlant"
	CabbagePlant.Parent = player.Inventory.Plants
	
	local TomatoPlant = Instance.new("IntValue")
	TomatoPlant.Name = "TomatoPlant"
	TomatoPlant.Parent = player.Inventory.Plants
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = player
	
	local Soil = Instance.new("IntValue")
	Soil.Name = "Soil"
	Soil.Parent = player.Inventory.Furniture
	
	local Hay = Instance.new("IntValue")
	Hay.Name = "Haybale"
	Hay.Parent = player.Inventory.Furniture
	
	local SmlDk = Instance.new("IntValue")
	SmlDk.Name = "SmallDeck"
	SmlDk.Parent = player.Inventory.Furniture
	
	local LgDk = Instance.new("IntValue")
	LgDk.Name = "LargeDeck"
	LgDk.Parent = player.Inventory.Furniture
	
	local DkSr = Instance.new("IntValue")
	DkSr.Name = "DeckStairs"
	DkSr.Parent = player.Inventory.Furniture
	
	local LogSeat = Instance.new("IntValue")
	LogSeat.Name = "LogSeat"
	LogSeat.Parent = player.Inventory.Furniture
	
	local CmpFre = Instance.new("IntValue")
	CmpFre.Name = "Campfire"
	CmpFre.Parent = player.Inventory.Furniture
	
	local Flag = Instance.new("IntValue")
	Flag.Name = "Flag"
	Flag.Parent = player.Inventory.Furniture
	
	local Wall = Instance.new("IntValue")
	Wall.Name = "Wall"
	Wall.Parent = player.Inventory.Furniture
	
	local GrnScrn = Instance.new("IntValue")
	GrnScrn.Name = "GreenScreen"
	GrnScrn.Parent = player.Inventory.Furniture
	
	local Chair = Instance.new("IntValue")
	Chair.Name = "Chair"
	Chair.Parent = player.Inventory.Furniture
	
	local Table = Instance.new("IntValue")
	Table.Name = "Table"
	Table.Parent = player.Inventory.Furniture
	
	local Bed = Instance.new("IntValue")
	Bed.Name = "Bed"
	Bed.Parent = player.Inventory.Furniture
	
	local playerUserId = "Player_"..player.UserId
	
	local success, errormessage = pcall(function()
		Data = Inventory:GetAsync(playerUserId)
	end)
	
	if success then
		WheatSeed.Value = Data.Wheat
		StrawberrySeed.Value = Data.Strawberry
		CarrotSeed.Value = Data.Carrot
		WatermelonSeed.Value = Data.Watermelon
		PotatoSeed.Value = Data.Potato
		CoconutSeed.Value = Data.Coconut
		BananaSeed.Value = Data.Banana
		PineappleSeed.Value = Data.Pineapple
		CabbageSeed.Value = Data.Cabbage
		TomatoSeed.Value = Data.Tomato
		WheatPlant.Value = Data.WheatPlant
		CarrotPlant.Value = Data.CarrotPlant
		PotatoPlant.Value = Data.PotatoPlant
		CabbagePlant.Value = Data.CabbagePlant
		TomatoPlant.Value = Data.TomatoPlant
		Cash.Value = Data.Cash
		Soil.Value = Data.Soil
		Hay.Value = Data.Hay
		SmlDk.Value = Data.SmallDeck
		LgDk.Value = Data.LargeDeck
		DkSr.Value = Data.DeckStairs
		LogSeat.Value = Data.LogSeat
		CmpFre.Value = Data.LogSeat
		Flag.Value = Data.Flag
		Wall.Value = Data.Wall
		GrnScrn.Value = Data.GreenScreen
		Chair.Value = Data.Chair
		Table.Value = Data.Table
		Bed.Value = Data.Bed
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	
	local Data = {
		Wheat = player.Inventory.Seeds.Wheat.Value,
		Strawberry = player.Inventory.Seeds.Strawberry.Value,
		Carrot = player.Inventory.Seeds.Carrot.Value,
		Watermelon = player.Inventory.Seeds.Watermelon.Value,
		Potato = player.Inventory.Seeds.Potato.Value,
		Coconut = player.Inventory.Seeds.Coconut.Value,
		Banana = player.Inventory.Seeds.Banana.Value,
		Pineapple = player.Inventory.Seeds.Pineapple.Value,
		Cabbage = player.Inventory.Seeds.Cabbage.Value,
		Tomato = player.Inventory.Seeds.Tomato.Value,
		WheatPlant = player.Inventory.Plants.WheatPlant.Value,
		CarrotPlant = player.Inventory.Plants.CarrotPlant.Value,
		PotatoPlant = player.Inventory.Plants.PotatoPlant.Value,
		CabbagePlant = player.Inventory.Plants.CabbagePlant.Value,
		TomatoPlant = player.Inventory.Plants.TomatoPlant.Value,
		Cash = player.Cash.Value,
		Soil = player.Inventory.Furniture.Soil,
		Hay = player.Inventory.Furniture.Haybale,
		SmallDeck = player.Inventory.Furniture.SmallDeck,
		LargeDeck = player.Inventory.Furniture.LargeDeck,
		DeckStairs = player.Inventory.Furniture.DeckStairs,
		LogSeat = player.Inventory.Furniture.LogSeat,
		CampFire = player.Inventory.Furniture.Campfire,
		Flag = player.Inventory.Furniture.Flag,
		Wall = player.Inventory.Furniture.Wall,
		GreenScreen = player.Inventory.Furniture.GreenScreen,
		Chair = player.Inventory.Furniture.Chair,
		Table = player.Inventory.Furniture.Table,
		Bed = player.Inventory.Furniture.Bed
		}
		
	local success, errormessage = pcall(function()
		Inventory:SetAsync(playerUserId, Data)
	end)
	
	if success then
		print("Data Saved Success")
	else
		print("Data Saved Unsuccessful")
		warn(errormessage)
	end
end)

You are saving an Instance in the table. Specifically, it starts Soil and ends at Bed in PlayerRemoving

And you can only save number,string and table

Try doing [“Item”] = Instance. That’s probably why but I’m not sure (Can we get the line number by the way)

Where would that go in the script?

Is there anyway to fix this script? It worked yesterday…
@partyunicorn1337 @Quwanterz

Simple, do NOT save an instance.

Well here’s the thing how can I change the “instance” to a value to save. I’m not really familiar with this error… If you can educate me on how to convert this then that would be great

You have to convert those instances into primitive types like numbers, strings, booleans, etc…

You can’t save instances to data stores.

So would I do in data Wheat.Value = because that said it was a complex thing and it needs a name

My question is, what do you want to save? Do you need to save the name and value or just 1 of the 2?

I want to save the value for the corresponding name in the invalues in the player

You can assign each item with a specific number value and plug them in when saving. The other alternative is to store the properties of each item. This can be done through tables and perhaps a for loop.

Let me explain the problem. You are not actually saving the value, but the Instance of the InstanceValue. This is easily fixed by adding Value instead, so it must be:

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	
	local Data = {
		Wheat = player.Inventory.Seeds.Wheat.Value,
		Strawberry = player.Inventory.Seeds.Strawberry.Value,
		Carrot = player.Inventory.Seeds.Carrot.Value,
		Watermelon = player.Inventory.Seeds.Watermelon.Value,
		Potato = player.Inventory.Seeds.Potato.Value,
		Coconut = player.Inventory.Seeds.Coconut.Value,
		Banana = player.Inventory.Seeds.Banana.Value,
		Pineapple = player.Inventory.Seeds.Pineapple.Value,
		Cabbage = player.Inventory.Seeds.Cabbage.Value,
		Tomato = player.Inventory.Seeds.Tomato.Value,
		WheatPlant = player.Inventory.Plants.WheatPlant.Value,
		CarrotPlant = player.Inventory.Plants.CarrotPlant.Value,
		PotatoPlant = player.Inventory.Plants.PotatoPlant.Value,
		CabbagePlant = player.Inventory.Plants.CabbagePlant.Value,
		TomatoPlant = player.Inventory.Plants.TomatoPlant.Value,
		Cash = player.Cash.Value,
		Soil = player.Inventory.Furniture.Soil.Value,
		Hay = player.Inventory.Furniture.Haybale.Value,
		SmallDeck = player.Inventory.Furniture.SmallDeck.Value,
		LargeDeck = player.Inventory.Furniture.LargeDeck.Value,
		DeckStairs = player.Inventory.Furniture.DeckStairs.Value,
		LogSeat = player.Inventory.Furniture.LogSeat.Value,
		CampFire = player.Inventory.Furniture.Campfire.Value,
		Flag = player.Inventory.Furniture.Flag.Value,
		Wall = player.Inventory.Furniture.Wall.Value,
		GreenScreen = player.Inventory.Furniture.GreenScreen.Value,
		Chair = player.Inventory.Furniture.Chair.Value,
		Table = player.Inventory.Furniture.Table.Value,
		Bed = player.Inventory.Furniture.Bed.Value
		}
		
	local success, errormessage = pcall(function()
		Inventory:SetAsync(playerUserId, Data)
	end)
	
	if success then
		print("Data Saved Success")
	else
		print("Data Saved Unsuccessful")
		warn(errormessage)
	end
end)
1 Like

You’re trying to store these, which are instances. You can only store numbers and strings (that being inside a table)

Change them to something like this:


Hay = player.Inventory.Furniture.Haybale.Name,
		SmallDeck = player.Inventory.Furniture.SmallDeck.Name,
		LargeDeck = player.Inventory.Furniture.LargeDeck.Name,
		DeckStairs = player.Inventory.Furniture.DeckStairs.Name,
		LogSeat = player.Inventory.Furniture.LogSeat.Name,
		CampFire = player.Inventory.Furniture.Campfire.Name,
		Flag = player.Inventory.Furniture.Flag.Name,
		Wall = player.Inventory.Furniture.Wall.Name,
		GreenScreen = player.Inventory.Furniture.GreenScreen.Name,
		Chair = player.Inventory.Furniture.Chair.Name,
		Table = player.Inventory.Furniture.Table.Name,
		Bed = player.Inventory.Furniture.Bed.Name

I don’t fully understand what you’re trying to do, but this should store the furniture. Unless you’re checking if the player owns the furniture. Anyway, storing instances worked back in the data persistence days (2011-2014), but that API is LONG outdated and won’t work at all.