DataStore Saving A Player's IntValue and BoolValue

Hey, I’m trying to make a dataStore script that saves the amount of cards a player has, the card level, and whether or not the card is owned. I’m not sure what’s wrong with it.

local ds = game:GetService("DataStoreService"):GetDataStore("CardSaving")
local cards_folder = game.ServerStorage.Cards

game.Players.PlayerAdded:Connect(function(plr)
  local cards_fold = Instance.new("Folder")
	  	cards_fold.Name = "Cards"
  	  	cards_fold.Parent = plr
	
	for _, v in pairs (cards_folder:GetChildren()) do
		
		local card = Instance.new("Folder")
		card.Name = v.Name
		card.Parent = cards_fold
		
		local cardOwned = Instance.new("BoolValue")
		cardOwned.Name = "CardOwned"
		cardOwned.Parent = card
		
		local cardAmount = Instance.new("IntValue")
		cardAmount.Name = "CardAmount"
		cardAmount.Parent = card
		
		local lvl = Instance.new("IntValue")
		lvl.Name = "Level" 
		lvl.Parent = card
		
		local Chloe = ds:GetAsync("Chloe".. plr.UserId)
		local KEKI = ds:GetAsync("KEKI".. plr.UserId)
		local Radley = ds:GetAsync("Radley".. plr.UserId)
		local Sabaku = ds:GetAsync("Sabaku".. plr.UserId)
		if v.Name == "Chloe" and Chloe ~= nil then
			print("Getting the data")
			local succ, msg = pcall(function()
					cardOwned.Value = (Chloe)
					cardAmount.Value = (Chloe)
					lvl.Value = (Chloe)
				end)
				if not succ then
					warn("Problem with getting and setting data "..msg)
			end
		elseif v.Name == "KEKI" and KEKI ~= nil then
			local succ, msg = pcall(function()
				cardOwned.Value = (KEKI)
				cardAmount.Value = (KEKI)
				lvl.Value = (KEKI)
			end)
			if not succ then
				warn("Problem with getting and setting data "..msg)
			end
		elseif v.Name == "Radley" and Radley ~= nil then
			local succ, msg = pcall(function()
				cardOwned.Value = (Radley)
				cardAmount.Value = (Radley)
				lvl.Value = (Radley)
			end)
			if not succ then
				warn("Problem with getting and setting data "..msg)
			end
		elseif v.Name == "Sabaku" and Sabaku ~= nil then
			local succ, msg = pcall(function()
				cardOwned.Value = (Sabaku)
				cardAmount.Value = (Sabaku)
				lvl.Value = (Sabaku)
			end)
			if not succ then
				warn("Problem with getting and setting data "..msg)
			end
		end	
	end
end)
		

game.Players.PlayerRemoving:Connect(function(plr)
	local succ, msg = pcall(function()
		local Chloe = {}
		local KEKI = {}
		local Radley = {}
		local Sabaku = {}
	for _, v in pairs (plr.Cards:GetChildren()) do
			local card = v
			for _, v in pairs (card:GetChildren()) do
				if card.Name == "Chloe" then
					table.insert(Chloe,{v.Name, v.Value})
				elseif card.Name == "KEKI" then
					table.insert(KEKI, {v.Name, v.Value})
				elseif card.Name == "Radley" then
					table.insert(Radley, {v.Name, v.Value})
				elseif card.Name == "Sabaku" then
					table.insert(Sabaku, {v.Name, v.Value})
				end
			end
			
		end
		ds:SetAsync("Chloe"..plr.UserId, Chloe)
		ds:SetAsync("KEKI"..plr.UserId, KEKI)
		ds:SetAsync("Radley"..plr.UserId, Radley)
		ds:SetAsync("Sabaku"..plr.UserId, Sabaku)
		
  end)

  if not succ then
    warn("Problem with saving data ".. msg)
  end
end)

Thanks!

Lua and almost every other programming language is case sensitive, instead of using: :SetAsync() and :GetAsync()
use: :setAsync() and :getAsync()

1 Like

It still doesn’t save the data, I’ve also tried it in game.

It’s case sensitive, so you have to do SetAsync and GetAsync instead of setAsync and getAsync

The thing is, i can only talk out of my own experience on working with the DatastoreService, it never worked for me with :SetAsync() or :GetAsync(), it only works for me with: :setAsync() and :getAsync()

Note: Developer.roblox.com isn’t always right

Exampel:
This one works for me:

	NewWarnings.Changed:Connnect(function(value)
		local Success,ErrorMessage = pcall(function()
			WarnData:setAsync(WarnKey..Player.UserId,value)
		end)
		if not Success then
			warn("Something went wrong while saving the data for "..Player.Name.."\nError: "..ErrorMessage)
		end
	end)

But this one doesn’t:

	NewWarnings.Changed:Connnect(function(value)
		local Success,ErrorMessage = pcall(function()
			WarnData:SetAsync(WarnKey..Player.UserId,value)
		end)
		if not Success then
			warn("Something went wrong while saving the data for "..Player.Name.."\nError: "..ErrorMessage)
		end
	end)