How to save StringValues with their values as well?

Hi everyone,

I have been trying to save some StringValues inside of a folder, inside of the player. I can get the StringValues themselves to save and load accordingly (with the correct names), but I’m not sure on how to make them go with their corresponding values that are supposed to be saved with them.

This is the structure of the folder inside of the player, and each one of these StringValues has a different value defined inside (pic 2)
image
image

This is how I create and load data if it exists, but it won’t create it with the values inside of it.

		------ Custom Keybinds ------

		if CustomKeybindsData then
			for _, keybindType in pairs(CustomKeybindsData) do
				local keybindValue = Instance.new("StringValue")
				keybindValue.Name = keybindType
				keybindValue.Parent = customKeybindsFolder
			end

		else -- If values don't exist, create them
			for i = 1,9 do
				local newKeybind = Instance.new("StringValue")
				newKeybind.Name = "JingleA"..i
				newKeybind.Parent = customKeybindsFolder
			end
		end

How would I go about gettting the StringValues with the values inside of them to save and able to load? Hopefully this makes sense of what I’m trying to do, if not then I can try and explain a little better :))

Thanks in advance :slight_smile:

2 Likes

https://developer.roblox.com/en-us/api-reference/class/DataStoreService

You’ll need to use the DataStoreService for persistent data (data which can be saved and loaded between sessions).

Are you referring to the Keys? Ie

(Key) JingleA1 | “Value”

I was already using datastores, but couldn’t figure out how to save two peices of data at the same time. It has been solved using arrays stored in a table, so each name and value is stored in the array, and each array is stored in the table. Thanks for your help though :slight_smile:

Thanks for your help, I have solved this using arrays which store each value, and then the arrays are stored in a table and reloaded in the order needed for the values to match.

I wasn’t sure if you were aware of the service as your post made no mention of it & the script didn’t contain any reference to it either.

But yes, you’d store the StringValue’s names as the keys of some dictionary and the associated values of those keys would be the values of those StringValue instances.

That dictionary would then be saved/loaded to & from the DataStore when required.

1 Like

Yeah, thanks. I didn’t post the entire script as there are lots of functioning things in there that weren’t necessary to post here but that was all including elsewhere in the script. I appreciate your help, and glad it could be resolved :slight_smile:

That’s the correct way to do it. Mark your response as solved, please.

1 Like