I need to save name and value

i saved the valu of the name and the value to datastore, and when the player leaves it does save ichecked all the values in the table but when i join back i cant set it to those values, it takes the defult name and value from replicatedstorage

-- 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()
			pcall(function()
				for val,v in pairs(own) do
					if clone:FindFirstChild(val) then
						print(v[("name")])
						print(v[("value")])
						clone[val].Value = v[("value")]
						clone[val].Name = v[("name")]
						
					end
				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] = {["value"] = child.Value; ["name"] =child.Name}
		end
		ownedcharms[charm.Name] = tbl
		print(ownedcharms)
	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)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Did you… Uhh remember to uncomment the line of code at the top?

yes yes i did i accidentally copied it like that

Could you provide the full script?

nevermined i solved it haha there is the script:

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
local kaki = string.gsub(i,“%d”,“”)
print(kaki)
if CHarms:FindFirstChild(kaki) then
local clone = CHarms[kaki]:Clone()
pcall(function()
for val,v in pairs(own) do
if clone:FindFirstChild(val) then
clone[val]:FindFirstChildWhichIsA(“IntValue”).Name = v[(“name”)]
clone[val]:FindFirstChildWhichIsA(“IntValue”).Value = v[(“value”)]
end
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 num , child in pairs(charm:GetChildren()) do
tbl[num] = {[“value”] = charm[(num)]:FindFirstChildWhichIsA(“IntValue”).Value; [“name”] = charm[(num)]:FindFirstChildWhichIsA(“IntValue”).Name}
end
ownedcharms[charm.Name…i] = tbl
end

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

players.PlayerRemoving:Connect(plrLeaving)

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