Save also the names of the values

hello! some awesome guy already helped me with it but i need to know if there is a way to save also the names of the values, since i need to change them mid game in addition to their values
i hope you get what i mean haha

players.PlayerAdded:Connect(function(plr)
	local charms = Instance.new("Folder",plr)
	charms.Name = "Charms"

	local owendC = plr:WaitForChild("Charms")
	local charmsowned = {}
	pcall(function()
		charmsowned = data:GetAsync(plr.UserId) or {}
	end)

	for i,own in pairs(charmsowned) do
		if CHarms:FindFirstChild(i) then
			local clone = CHarms[i]:Clone()
			for val,v in pairs(own) do
				if clone:FindFirstChild(val) then
					clone[val].Value = v
				end
			end
			clone.Parent = owendC
		else
			owendC = charmsowned
		end
	end
end)

function plrLeaving(plr)
	local ownedcharms = {}
	for i , charm in pairs(plr.Charms:GetChildren()) do
		local tbl = {}
		for _  , child in pairs(charm:GetChildren()) do
			tbl[child.Name] = child.Value
		end
		ownedcharms[charm.Name] = tbl
	end

	local s,e = pcall(function()
		data:SetAsync(plr.UserId,ownedcharms)
	end)
	if s then
		print(s)
	else
		print(e)
	end
end

players.PlayerRemoving:Connect(plrLeaving)

2 Likes

Can you please be more specific about what the problem is and what you want to achieve? Also, you made a mistake in the script: owendC, you probably were reffering to the owned charms, so it would be ownedC.

2 Likes

ummm well i this code saves both the folders in the player’s “charms” folder and the intvalues in thoes folders, the problem is that i want to change the name of the intvalues also and save it, not just the value but i am kinda stuck, i hope i cleared it if not im sorry

1 Like

{
[“WarmLight”] = ▼ {
[“ID”] = 111111,
[“dsfghfgh”] = 0,
[“sfghsfgh”] = 0,
[“two”] = 0
}
}

this is the table after midgame i change the names of the folders to some random letters, but i just dont know how to set it when the player joins, i only could set the values

1 Like

why do you have charmsowned and ownedcharms

1 Like

it saves normally idk, this scripts works but i just dont know how to save also the names of the values, and not just the values, since i am cloning it from replicated storage, and the names of the values reset to the names they have in replacted storage

1 Like

I was not asking what this piece of code is, but rather pointing out the supposed spelling mistake.

1 Like

but this has nothing to do with the problem, i changed it already

1 Like