Datastore doesnt save multiple values

Why does my datastore only saves 2 values numbervalue and BoolValue and when i try to.add another BoolValue it wont work. The only two values only works

--- ----- DataStore
local dss = game:GetService("DataStoreService")
local db = dss:GetDataStore("IvanozDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local ownsTool = Instance.new("BoolValue",player)
	ownsTool.Value = false
	ownsTool.Name = "ownsTool"
	
	local ownsMagnumTool = Instance.new("BoolValue",player)
	ownsMagnumTool.Value = false
	ownsMagnumTool.Name = "ownsMagnumTool"
	
	local coins = Instance.new("NumberValue",leaderstats)
	coins.Name = "Coins"
	coins.Value = 200
	
	
	local ownsToolData
	local ownsMagnumData
	local coinsData

	local succes,errorMessage = pcall(function()
		ownsToolData = db:GetAsync(player.UserId.."-ownsTool")
		coinsData = db:GetAsync(player.UserId.."-coins")
		ownsMagnumData = db:GetAsync(player.UserId.."-ownsMagnumData")
	end)

	if succes then
		ownsTool.Value = ownsToolData
		coins.Value = coinsData
		ownsMagnumTool.Value = ownsMagnumData
	else
		warn(errorMessage)
	end
	
	player.CharacterAdded:Connect(function(char)
		if player.ownsTool.Value == true and not player.StarterGear:FindFirstChild("Axe") then
			game.ServerStorage:WaitForChild("Tools").Axe:Clone().Parent = player:WaitForChild("StarterGear")
			game.ServerStorage:WaitForChild("Tools").Axe:Clone().Parent = player:WaitForChild("Backpack")
		end
		if player.ownsMagnumTool.Value == true and not player.StarterGear:FindFirstChild("Magnum") then
			game.ServerStorage:WaitForChild("Tools").Magnum:Clone().Parent = player:WaitForChild("StarterGear")
			game.ServerStorage:WaitForChild("Tools").Magnum:Clone().Parent = player:WaitForChild("Backpack")
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	db:SetAsync(player.UserId.."-ownsTool",player.ownsTool.Value)
	db:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
    db:SetAsync(player.UserId.."-ownsMagnumTool",player.ownsMagnumTool.Value)
end)

1 Like

You shouldn’t be using multiple datastores for different stuff, you should be saving it all under one datastore and save the data in a table.

3 Likes

adding to what @WooleyWool said
you can store the values through a table!
here’s an example on how you can Store/Recieve the data!

-- OnPlayerRemoving
db:SetAsync(player.UserId.."-Data",
{player.ownsTool.Value,player.leaderstats.Coins.Value,player.ownsMagnumTool.Value})
-- OnPlayerJoining
local data
local success,errmsg = pcall(function()
data = db:GetAsync(player.UserId.."-Data")
end)
-- Recieving the data.
if success then
for i,v in pairs(data) do
print(data[1]) -- OwnsTool Value
print(data[2]) -- Coins Value
print(data[3]) -- ownsMagnumTool Value
else
warn(errmsg)
end
end
2 Likes

Saving multiple values through table:

local function saveData(player)
	local tableToSave = {
		player.Variaveis.Money.Value;		
		player.Variaveis.Tutorial_Passos.Value;
		math.round(tick());
		player.Variaveis.Level.Value;
		player.Variaveis.Municao_Atual.Value;
		
		player.Variaveis.Hideout.Sujeira_Sala1.Value;
		player.Variaveis.Hideout.Sujeira_Sala1T.Value;
		tabela_amigos -- this is another table inside this table
	}
	local success, err = pcall(function()
		dataStore:SetAsync(player.UserId, tableToSave)
		--dataStore:SetAsync(player.UserId.."amigos", tabela_amigos)
	end)
	if success then
		print("Data foi salvo!")
	else
		print("Data NÃO foi salvo!!!")
		warn(err)
	end
end


game:BindToClose(function()
	saveData(player) 
end)
2 Likes

this video might help

1 Like

i really appreciate for spending your time on this my friend

1 Like