I am trying to make a ProfileService stat script where you have an inventory, wins, and gold. But for some reason no matter what I do the profile.Data.Inventory is nil.
Here is the script:
local ProfileService = require(game.ReplicatedStorage.ProfileService)
local Players = game:GetService("Players")
local Profiles = {}
local saveStructure = {
Wins = 0;
Gold = 0;
Inventory = {
};
}
local PlayerProfileStore = ProfileService.GetProfileStore("ProfileStore", saveStructure)
local function PlayerDataLoaded(player)
local profile = Profiles[player]
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = folder
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Parent = player
local Inventory = Instance.new("Folder")
Inventory.Name = "Inventory"
Inventory.Parent = player
print(profile.Data.Wins)
print(profile.Data.Gold)
wins:GetPropertyChangedSignal("Value"):Connect(function()
profile.Data.Wins = wins.Value
end)
gold:GetPropertyChangedSignal("Value"):Connect(function()
profile.Data.Gold = gold.Value
end)
local val = game.ReplicatedStorage.Value:Clone()
val.Name = "Default Explosion"
val.Value = "Explosion"
val:SetAttribute("Image", "1")
val.Parent = Inventory
for i,v in ipairs(profile.Data.Inventory) do
local value = game.ReplicatedStorage.Value:Clone()
value.Name = v[1][1]
value.Value = v[1][2]
value:SetAttribute("Image", v[1][3])
value.Parent = Inventory
end
spawn(function()
local profile = Profiles[player]
if profile ~= nil then
print(profile)
wins.Value = profile.Data.Wins
gold.Value = profile.Data.Gold
Inventory = profile.Data.Inventory
end
end)
end
local function PlayerAdded(player)
local profile = PlayerProfileStore:LoadProfileAsync("Player_" .. player.UserId, "ForceLoad")
if profile ~= nil then
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick("Your profile has been loaded remotely. Please rejoin.")
end)
if player:IsDescendantOf(Players) then
Profiles[player] = profile
PlayerDataLoaded(player)
else
profile:Release()
end
else
player:Kick("Unable to load saved data. Please rejoin.")
end
end
for _, player in ipairs(Players:GetPlayers()) do
spawn(function()
PlayerAdded(player)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = Profiles[player]
if profile ~= nil then
--for i, v in pairs(player:WaitForChild("Inventory"):GetChildren()) do
--if not profile.Data.Inventory[v.Name] then
-- table.insert(profile.Data.Inventory, {{v.Name, tostring(v.Value), v:GetAttribute("Image")}})
--end
-- end
profile:Release()
end
end)
return Profiles