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

If this is a problem with showing them on GUIs, then you can use string.format("%.2f", number) to round it to 2 decimal places.

1 Like

That sucks… I’ll hopefully reply in a day, once I rewrite everything :sob:
I already did the deserialization, so I have to rewrite that too…

1 Like

So far I have this:

Scale = item.Scale – doesn’t like (gives an error)

Scale = { X = item.Scale.X, Y = item.Scale.Y, Z = item.Scale.Z } – likes (no error)


Update

Whats with all the string manipulation stuff to get the material and shape? Just do something like this:

BasePart.Material.Name -- For name
BasePart.Shape.Name -- For shape

Otherwise, the other stuff looks good to me

1 Like

Thank you! It works :smiley:

30 chАrаcters

Honestly, your previous idea of saving the numbers as strings might be more efficient to store than tables. For example, if you tostring’ed a BasePart’s color it would be “1, 1, 1” and to turn it back to its original values you could tonumber these numbers after using string:Split on it

What do you think I should prioritize? Performance or Internet usage? My entire “game” is on a local script, so loading in and saving is the only time a server script is needed. I also want my friend to be able to play on his late 2000s ThinkPad :joy:

Waiting for something to load for 2 extra minutes doesn’t seem that bad imo… So I’m thinking to prioritize performance at the cost of datastorage size. But please, provide a counterargument so I can decide best :smiley:

I just wanna chime in here. Instead of saving the color as an array, why not save it as a HexValue instead? ToHex() returns a string of a colors hex value.

dataTable = {
    ["Color"] = item.Color:ToHex()
}

And then when the parts color is to be set,

local dataTable = loadedDataTableHere

item.Color = Color3.fromHex(dataTable["Color"])
2 Likes

For your entire game, you should prioritize performance. If your entire game is client-sided, then there isn’t a lot of information being sent from their server to the client, so there won’t be that much traffic. Also, data saving has nothing to do with how long the client takes to load because it’s on the server and generally doesn’t take long.

Overall, I mentioned you should think about the most efficient way to save data because roblox’s data stores have limits. Also, the larger the data the longer it takes to get it. Now let’s get technical.

Dictionaries usually take more space than basic data types such as strings, booleans, and numbers because they’re more complex so using strings will help a lot.

I would personally do this for Vector3 and CFrame data types:

local BasePlate = workspace.Baseplate

local Data = {
	Position = tostring(BasePlate.Position),
	Size = tostring(BasePlate.Size),
	Orientation = tostring(BasePlate.Orientation)
}

local function Convert(DataString:string) 
	local Split = DataString:split(", ")

	local Result = {}

	for Index, Value in Split do
		local Number = tonumber(Value) 

		if not Number then
			warn(`Index of [{Index}] has been automatically converted to 0.`)
			Number = 0 
		end

		table.insert(Result, Number)
	end

	return table.unpack(Result)
end

local Position = Vector3.new(Convert(Data.Position))
local Size = Vector3.new(Convert(Data.Size))
local Orientation = Vector3.new(Convert(Data.Orientation))

W this works

30 сhаrасtеrs

1 Like

Looks great!

One question though:
You have an edge case at lines 19 through 22
When would this edge case be needed?

Otherwise, perfect, I’ll be using this too! My God, y’all are on fire! I’m so thankful I made a forum post :smiley:

You’re right. The scenario in which the string is not a perfect number is extremely unlikely. You don’t need the check; I just have a habit of expecting the unexpected.

Edit: Also, I think strings are good because they don’t lose information, unlike numbers. When saving numbers with decimals I think datastores round it off making you lose precision.

1 Like

Interesting :joy:
This is like my second time coding this month (I’ve been coding on and off for like 3 years now though), so I’m not too experienced, hence why I’m receiving all the help I can get :stuck_out_tongue:
Maybe I’ll get into that habit after some time, who knows :smiley:

Awesome! I’ll be including everybody’s code! Thank you all so much! But now I don’t know who to mark as the solution… :rofl:

Just pick the reply that you feel helped you the most so that others can know the problem has been solved

The problems will never get solved, because when one gets solved, two more pop up, and a third one gets un-solved :rofl: :rofl: :rofl:

One more thing: Any advice for:

CustomPhysicalProperties = { 
Density = item.CustomPhysicalProperties.Density, 
Elasticity = item.CustomPhysicalProperties.Elasticity, 
ElasticityWeight = item.CustomPhysicalProperties.ElasticityWeight, 
Friction = item.CustomPhysicalProperties.Friction, 
FrictionWeight = item.CustomPhysicalProperties.FrictionWeight 
}

Thank you so much!

Was your lack of reply intentional? Either way, it was a blessing in disguise, because it gave me time to rewrite your function so I can better wrap my head around it, and I realized I can also use it for the custom physical properties!

local function convertStringToVector(DataString:string) 
	
	local Result = {}

	for _, Value in DataString:split(", ") do

		table.insert(Result, tonumber(Value))
		
	end

	return table.unpack(Result)

end

Again, thank you so so much! :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

My lack of a reply was not intentional I was just doing something.

On the dev forum, I like to store stuff in variables so the reader can understand it better but it seems you understand the main function of it either way. It’s great you brainstormed by yourself to figure out you can use the function for PhysicalProperties :smile:

Edit: Forget saving the position and orientation separately and just use the CFrame. Just tostring it and then use the function to return it back to it’s original form

1 Like

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