Data not saving

So this is a follow up from a post I made like a couple days ago, ive tried many ways to get it functional but to no avail, this is the whole script

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("ds5")
local players = game:GetService("Players")
local rp = game:GetService("ReplicatedStorage")
local HTTP = game:GetService("HttpService")


players.PlayerAdded:Connect(function(player)
	wait(1)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local exp = Instance.new("IntValue")
	exp.Name = "Exp"
	exp.Parent = leaderstats
	
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Parent = leaderstats

	local weapons = Instance.new("Folder")
	weapons.Name = "Weapons"
	weapons.Parent = player
	
	local skills = Instance.new("Folder")
	skills.Name = "Skills"
	skills.Parent = player
	
	local amulets = Instance.new("Folder")
	amulets.Parent = player
	amulets.Name = "Amulets"
	
	local armour = Instance.new("Folder")
	armour.Name = "Armour"
	armour.Parent = player
	
	local materials = Instance.new("Folder")
	materials.Name = "Materials"
	materials.Parent = player
	
    local PlayerUserId = "player_"..player.UserId
	local Data 
	local success, err = pcall(function()
	   Data = ds:GetAsync(PlayerUserId)
	end)
	if success and Data ~= nil then
		local Data = HTTP:JSONDecode(Data)
		print("has data")
		wait(5)
		for i, v in pairs(Data.Items) do
			
			if rp.Armour:FindFirstChild(v) then
				local armour = rp.Armour:FindFirstChild(v):Clone()
				armour.Parent = armour
			elseif rp.Skills:FindFirstChild(v) then
				local skill = rp.Skills:FindFirstChild(v):Clone()
				skill.Parent = skills
			elseif rp.Weapons:FindFirstChild(v) then
				local weapon = rp.Weapons:FindFirstChild(v):Clone()
				weapon.Parent = weapons
			elseif rp.materials:FindFirstChild(v) then
				local mat = rp.materials:FindFirstChild(v):Clone()
				mat.Parent = materials
			end
		end
		coins.Value = Data.Coins
		exp.Value = Data.Exp
		level.Value = Data.Level
	else
		print("no data")
		coins.Value = 0
		exp.Value = 0
		level.Value = 0
		-- No Data
	end
end)
	
	

local save_Data = function(v)
	local PlayerUserId = "player_"..v.UserId
	local coins = v.leaderstats.Coins
	local exp = v.leaderstats.Exp.Value
	local level = v.leaderstats.Level.Value
	local item_Data = {}
	local items = {
		v.Weapons:GetChildren(), 
		v.Skills:GetChildren(),
		v.Amulets:GetChildren(),
		v.Materials:GetChildren(),
		v.Armour:GetChildren()
	}
	for index, items in pairs(items) do
		for i, v in pairs(items) do
			table.insert(item_Data, 1, v.Name)
		end
	end
	
	local data = {
		Items = item_Data,
		Coins = coins,
		Exp = exp,
		Level = level
	}
	local ToSave = HTTP:JSONEncode(data) -- save this
    print("attempting to save")
	local success, err = pcall(function()
		ds:SetAsync(PlayerUserId, ToSave)
	end)
	if success then
		print("data saved succesfully")
	else
		print(err)
	end
end

game:BindToClose(function()
	for i, v in pairs(game.Players:GetChildren()) do
		save_Data(v)
	end
end)
1 Like

Why do you have items defined twice?
Does the JSONEncoded data look fine? Maybe print it to see if it is.

1 Like

Not only that but i tried to save the coins not the coins.Value, meaning the data was saving fine I just didn’t get the coins back (which is what I was testing)