Saving Multiple String Values in an Already Existing Folder

so how would I use it to save my table?

First of all watch the beginner tutorial video under the thread or just try to understand the post. After you’ve done this, you’ll need to open the players data store then set the date store’s value to your new data. Also, you need to destroy the players datastore when they leave. To get the data you can just use .find to get the players datastore and read its value

This is necessary to save just 3 string values? Is there a simpler way to do it? Because I keep running into errors

I just got online when I saw this but I’ll show you a simplified way of how I would do it.
I didn’t have time to comment on anything so just ask if you’re confused about something

Edit: I noticed I didn’t add loading the data onto the values so I added that. Also, removed unnecessary code.

local Players = game:GetService("Players")

local SDM = require(Path.To.Module)

local Template = {
	Primary = "None",
	Secondary = "None",
	Melee = "None"
}

local function PlayerAdded(Player:Player)
	local PlayerDS = SDM.new("Example", Player.UserId)

	if PlayerDS:Open(Template) ~= "Success" then Player:Kick("Unable to load data!") return end

	local function CreateStringValues(Name:string, Parent:Instance) : StringValue
		local Uhh = Instance.new("StringValue")
		Uhh.Name = Name
		Uhh.Value = PlayerDS.Value[Name]
		Uhh.Parent = Parent

		local Connection:RBXScriptConnection;
		Connection = Uhh.Changed:Connect(function(value: string) 
			if not PlayerDS.State then 
				if Connection then
					Connection:Disconnect()
					Connection = nil
				end
				
				return 
			end

			PlayerDS.Value[Name] = value	
		end)
	end

	local Folder = Instance.new("Folder")
	Folder.Name = "Folder"
	Folder.Parent = Player

	for I, X in pairs(Template) do
		CreateStringValues(I, Folder)
	end
end

local function PlayerRemoving(Player:Player)
	local FoundDS = SDM.find("Example", Player.UserId)
	if FoundDS then FoundDS:Destroy() end
end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

What is does Uhh represent and can I save it in an already existing folder instead of making a new one?

I didn’t know how to name “Uhh” sorry :frowning:

  1. “Uhh” represents a stringValue.

  2. In the loop you can pass a different parent for the stringValues created. This means you can delete the code that creates a new folder.

  3. Does the code work for you?

Btw wanted to add this… If you change the string value in the folder during run time it will automatically save in the datatstore so you don’t have to worry about manually saving data when a player leaves