Cannot store dictionaries in datastores

I’m trying to save a player’s equipped killer right now, It worked well before i added the “EquippedKiller” variable, Yet it’s not working.

Here is the error:
image

playerData = {
				["Cash"] = 500;
				["Violence"] = 1;
				["EquippedKiller"] = serverstorage.Characters.Killers.Equinox.Equinox.Name
			}

Some feedback would be nice. Thank you!

1 Like

what is the value of serverstorage.Characters.Killers.Equinox.Equinox.Name?

1 Like

The issue here is the text you are saving is not within the valid character set of Roblox, probably from the EquippedKiller value.

here is a post I made explaining their exploits and stuff, could help you get more insight on it.

2 Likes

The name of the model i want to use.

Could you send a screenshot/copy and paste it?

As in where the model is located? (Sorry if i don’t understand)

The name of said model, probably copy and paste it.

try this

playerData = {
				Cash = 500;
				Violence = 1;
				EquippedKiller = serverstorage.Characters.Killers.Equinox.Equinox.Name
			}

also equipped killer makes no sense cause equinox.name is equinox

Still unfortunately doesn’t work.

then its probably because youre using a string as the value, try making a table with all the names and assign them a value and do

local Killers = {"name" = 1, "name" = 2}

EquippedKiller = Killers[serverstorage.Characters.Killers.Equinox.Equinox.Name]

I think issue here is what you’re trying to save data in table. Try to save data like that:

playerData = {
	["Cash"] = 500;
	["Violence"] = 1;
	["EquippedKiller"] = serverstorage.Characters.Killers.Equinox.Equinox.Name
}

playerData = table.concat(playerData, "/")

if you dont know how does this work, ask me

whats the

"/"

for? im confused

it makes it like “value1/value2/value3/etc” but i dont think it works on dicitionaries

basically to seperate values and if you want, you can use any symbol you want. table.concat(playerData, “/”) will return: “500/1/Equinox”
In example: if you want, you can use | to separate them, then it will return: “500|1|Equinox”

I also forgot to say if you want to get data back as a table, then you will need to use string.split
Basically like that:

-- if we want to save our data, we need to save it as a string (since datastores can only save strings, numbers and booleans i think)
local playerData = {
	["Cash"] = 500;
	["Violence"] = 1;
	["EquippedKiller"] = serverstorage.Characters.Killers.Equinox.Equinox.Name
}

playerData = table.concat(playerData, "/") -- basically you can change "/" to anything you want
--                                            but i personaly like to use this symbol

-- if we want to get our data back as a table, then we need to use string.split() and it will return our table that we have saved as a string
local playerData = string.split(playerData, "/") -- if you have used a different symbol, then change "/" to that symbol

I hope you understand now how does it work

why not just do

playerData = {
				["Cash"] = 500;
				["Violence"] = 1;
				["EquippedKiller"] = "Equinox"
			}
1 Like

assuming the code you sent is at DataLoad, line 94

Is there a child instance of the “Equinox” model who’s name is set to "Name"?

Use JSONEncode to turn you dictionary into a string, and JSONDecode to make the string back into the original dictionary.

1 Like

This sounds like a bad idea to not maintain a 1FN equivalent, aka bringing data altogether via the form of a string, instead of just keeping a dictionary form. Not only do you need to forget about the keys (you tightly tie data together), but it is also impossible to maintain proper data versioning across time, especially with legacy data you may no longer want to save : you would need to keep the legacy datum, or elaborate some filler techniques.
Relational databases have principles. The 1st normal form tells you that every field should remain atomic. In a nosql db, this principle should be reflected by not doing string manipulations to save data. Dictionaries are the way to go as it removes the dependance of each data that your solution obliges you to endure.

Now the non-UTF8 char issue may be due to either some input in the script, blank character etc, or in the model’s name. I would personally rewrite the entirety of the dictionary, especially if it was written using any LLM. This issue should not happen if the code was written using solely ascii characters.

2 Likes

JSONEncode will error on non-utf8 characters, meaning we would have the same issue here.