Only leaderstats folder saving?

I have 2 folders here, a BackendStats and leaderstats, the backend stats is stuff I don’t want to be displayed in the leaderstats. Currently only the leaderstats folder saves but the BackendStats doesn’t. I went over the code multiple times and I cannot find anything wrong, then again I do not have much experience with DataStores. To sum it all up I do not know why the values in the BackendStats are not saving.


local RepStorage = game:GetService("ReplicatedStorage")

--//Datastore
local DataStoreService = game:GetService("DataStoreService") 
local dataStore = DataStoreService:GetDataStore("Test") 

--//Items
local basic01Hoe = RepStorage:WaitForChild("Starter Sickle")

--//Function
local function saveData(player) 
	local tableToSave = { 
		player.leaderstats.CurrentHoe.Value,
		player.leaderstats.StorageCap.Value,
		player.leaderstats.CropCount.value,
		player.BackendStats.Multiplier.Value
		
	} 

	local success, errorMessage = pcall(dataStore.SetAsync, dataStore, player.UserId, tableToSave) --Checks if datastore succeeded

	if success then 
		print("Data has been saved!") 
	else 
		print("Data has not been saved!") 
	end
end

--//leaderstats
game.Players.PlayerAdded:Connect(function(player) 
	player.CharacterAdded:Wait() 
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats" 
	leaderstats.Parent = player 
	
	
	
	
	local currentHoe = Instance.new("StringValue")
	currentHoe.Name = "CurrentHoe"
	currentHoe.Parent = leaderstats
	currentHoe.Value = "basic01"
	
	local cropCount = Instance.new("IntValue")
	cropCount.Name = "CropCount"
	cropCount.Parent = leaderstats
	cropCount.Value = 1
	
	
	local storageCap = Instance.new("IntValue")
	storageCap.Name = "StorageCap"
	storageCap.Parent = leaderstats
	storageCap.Value = 10;
	
	
	local backendStats = Instance.new("Folder")
	backendStats.Name = "BackendStats"
	backendStats.Parent = player
	
	local multiplier = Instance.new("IntValue")
	multiplier.Name = "Multiplier"
	multiplier.Value = 1
	multiplier.Parent = backendStats
	
	print(player.BackendStats.Multiplier.Value)
	
	local data = nil 

	local success, errorMessage = pcall(function() 
		data = dataStore:GetAsync(player.UserId) 
	end)

	if success and data then 
		currentHoe.Value = data[1]
		storageCap.Value = data[2]
		cropCount.Value = data[3]
		
		if currentHoe.Value == "basic01" then
			local clone = basic01Hoe:Clone()
			clone.Parent = player.Backpack
		end
	else 
		print("The Player has no Data!") 
		warn(errorMessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player) 
	saveData(player) 
end)

game:BindToClose(function() 
	for _, player in ipairs(game.Players:GetPlayers()) do 
		task.spawn(saveData, player) 
	end
end)
2 Likes

I see the issue,the issue is you never do this

Multiplier.value = data(4)

1 Like

How did I not notice this, thank you so much!

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