Error When Saving Model [ProfileService]

Hello, I am trying to save models, but it doesn’t save because it states this following error: DataStoreService: CantStoreValue: Cannot store in data store. Data stores can only accept valid UTF-8 characters. API: UpdateAsync, Data Store: Dev10

Here’s the code:

local MPS = game:GetService("MarketplaceService")
local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes

local Manager = {}

Manager.Profiles = {}

function Manager.AdjustRoks(player: Player, amount: number)
	local profiles = Manager.Profiles[player]
	
	if not profiles then return end
	
	profiles.Data.Roks += amount
	player.leaderstats.Roks.Value = profiles.Data.Roks
end

function Manager.SaveRoks(player: Player, ore: Model, destroyed: boolean) -- This is save code
	local Profiles = Manager.Profiles[player]
	if not Profiles then return end
	
	local OreTable = Profiles.Data.Ores
	
	if destroyed then
		table.remove(OreTable, table.find(OreTable, ore))
		
	else
		table.insert(OreTable, ore) 
	end
	
	
	print(OreTable)

end

return Manager

Here’s the Template if you need it:

local module = {
	Roks = 0,
	RoksMP = 1,
	Luck = 0,
	Ores = {}
}

return module

you can only save numbers, booleans, strings and tables in datastore

1 Like

The problem is that you can’t store values that are not numbers, booleans, strings, or tables (normal “types” we call), as @HafuPlay said. A way to store other types you can see here: How to save unsupported values in datastore easily

EDIT: According to your case. If you want to store a model, you could create a table called “ModelTable.” There, you store all of the model’s properties, child… and etc. That’s the only way of doing this, at least from my knowledge.

local ModelTable = {Name = Model.Name}
local Childrens = {}

for _, part in Model:GetChildren() do
    Childrens[part.Name] =  {CFrame = {part.CFrame.X, part.CFrame.Y, part.CFrame.Z}, Color = {...}}
end

ModelTable[Childrens] = Childrens
1 Like

Okay, thanks! I’m just going to save the properties and on from there.

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