Problem with ProfileService [DataStore Module]

Hello Everyone! I’m making right now DataStore for my game, and, when I was making it, I’ve created a folder with all treasures bool values. So when finding it, it will make value “true”. And I did it, but it’s not saving anything, and I have also a OwnedHalos folder that won’t be working either (I just didn’t implement it yet).

Here is a Data Server Script:

local PlayersService = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ProfileService = require(ReplicatedStorage.Server.Libs["ProfileService"])

local manager = require(script.Parent.Manager)
local template = require(ReplicatedStorage.Server.Data.Template)

local ProfileStore = ProfileService.GetProfileStore("Leaderstats", template)
local function leaderstats(player: Player)
	local profile = manager.Profiles[player]
	if not profile then return end
	
	-- // Folders
		-- Main
		local leaderstats = Instance.new("Folder", player)
		leaderstats.Name = "leaderstats"

		local values = Instance.new("Folder", leaderstats)
		values.Name = "Values"
		local codes = Instance.new("Folder", leaderstats)
		codes.Name = "Codes"
		local treasures = Instance.new("Folder", leaderstats)
		treasures.Name = "Treasures"

		-- Data
		local data = Instance.new("Folder", leaderstats)
		data.Name = "Data"

		local ownedHalos = Instance.new("Folder", data)
		ownedHalos.Name = "OwnedHalos"
	
	-- // Values
	local TableValues = {
		"City Opened", "Factory Opened",
		"Pyramid Opened", "Wall Opened",
		"isBinary", "Playing"
	}
	for _, value in pairs(TableValues) do
		local new = Instance.new("BoolValue", values)
		new.Name = tostring(value)
		new.Value = profile.Data.Values[value]
	end
	local coins = Instance.new("IntValue", leaderstats)
	coins.Name = "Coins"
	coins.Value = profile.Data.Coins
	
	local found = Instance.new("IntValue", leaderstats)
	found.Name = "Treasure Found"
	found.Value = profile.Data.Found
	
	local equippedHalo = Instance.new("StringValue", data)
	equippedHalo.Name = "Equipped Halo"
	equippedHalo.Value = profile.Data.EquippedHalo
	
	local TableTreasures = {}
	local MainFolder = workspace.Main:FindFirstChild("Treasures")
	for _, value in pairs(MainFolder:GetChildren()) do
		table.insert(TableTreasures, value.Name)
	end
	for i, treasure in pairs(TableTreasures) do
		local new = Instance.new("BoolValue", treasures)
		new.Name = TableTreasures[i]
		new.Value = profile.Data.Treasures[i]
		
		print(new.Name)
	end
end

local function playerAdded(player: Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	if profile == nil then
		player:Kick("Issue getting data, please rejoin.")
		return
	end
	profile:AddUserId(player.UserId)
	profile:Reconcile()
	
	profile:ListenToRelease(function()
		manager.Profiles[player] = nil
		player:Kick("Issue getting data, please rejoin.")
	end)
	if player:IsDescendantOf(PlayersService) == true then
		manager.Profiles[player] = profile
		leaderstats(player)
	else
		profile:Release()
	end
end
for _, player in PlayersService:GetPlayers() do
	task.spawn(playerAdded, player)
end

PlayersService.PlayerAdded:Connect(playerAdded)
PlayersService.PlayerRemoving:Connect(function(player: Player)
	local profile = manager.Profiles[player]
	if not profile then return end
	profile:Release()
end)

Template Module Script:

local module = {
	Coins = 100,
	Found = 0,
	Treasures = {
		["AlienChest"] = false,     ["DirtChest"] = false,      ["RoofChest"] = false,
		["ArticChest"] = false,     ["FishChest"] = false,      ["SacredChest"] = false,
		["BeachballChest"] = false, ["FridgeChest"] = false,    ["SandChest"] = false,
		["BedChest"] = false,       ["GlassChest"] = false,     ["SignChest"] = false,
		["BinaryChest"] = false,    ["GrassChest"] = false,     ["SnowChest"] = false,
		["BookChest"] = false,      ["HouseChest"] = false,     ["SteelChest"] = false,
		["BorderChest"] = false,    ["LampostChest"] = false,   ["StopsignChest"] = false,
		["BossChest"] = false,      ["LimestoneChest"] = false, ["TVChest"] = false,
		["BoxChest"] = false,       ["NPCChest"] = false,       ["TankChest"] = false,
		["CactusChest"] = false,    ["ObbyChest"] = false,      ["TentChest"] = false,
		["CaveChest"] = false,      ["OfficeChest"] = false,    ["TowerChest"] = false,
		["ChairChest"] = false,     ["PathChest"] = false,      ["TrampolineChest"] = false,
		["ChimenyChest"] = false,   ["PipeChest"] = false,      ["TreeChest"] = false,
		["CloudChest"] = false,     ["PyramidChest"] = false,   ["UmbrellaChest"] = false,
		["CoinChest"] = false,      ["RailingChest"] = false,   ["WindowChest"] = false,
		["DeathChest"] = false,     ["RoadChest"] = false,      ["WoodChest"] = false,
		["DeveloperChest"] = false, ["RockChest"] = false
	},
	Values = {
		["City Opened"] = false,
		["Factory Opened"] = false,
		["Pyramid Opened"] = false,
		["Wall Opened"] = false,
		["isBinary"] = false,
		["Playing"] = false
	},
	OwnedHalos = {},
	EquippedHalo = ""
}
return module

In Template Module Script I wrote every value by myself (It didn’t work with for, that’s why I did it by myself.)

This is how looks script in Hitbox:

local profile = manager.Profiles[player]
event1:FireClient(player,text,clr,dif)
	
profile.Data.Found += 1; profile.Data.Treasures[chest_name] = true; 
print(profile.Data.Treasures[chest_name])
db = true; wait()
	
player.leaderstats["Treasure Found"].Value = profile.Data.Found
boolValue.Value = profile.Data.Treasures[chest_name]
	
print(boolValue)
	
task.wait(5); db = false

The problem is, that everything is saving properly, but only tables and folders not saving.
And I can’t fix this problem like a month. So if someone can help, that would be really appreciated! Thanks.

1 Like