Ive been trying to make an inventory system, but as soon as i am almost finished, more errors keep popping up. So here’s the script:
local DEFAULT_PROFILE = {
-- {{ INVENTORY }} --
["Wooden Pickaxe"] = 1,
}
local ProfileService = require(script.ProfileService)
local Players = game:GetService("Players")
local GameProfileStore = ProfileService.GetProfileStore(
"mainsavedata_001",
DEFAULT_PROFILE
)
local Profiles = {}
local function loadUserData(player : Player, profile)
for i,_ in pairs(profile.Data) do
local newVal = Instance.new("IntValue")
newVal.Value = profile.Data[i]
newVal.Name = i
newVal.Parent = player:WaitForChild("Inventory")
end
for _,v : IntValue in pairs(player:GetDescendants()) do
if (v:IsA("StringValue") or v:IsA("NumberValue") or v:IsA("IntValue")) and (v.Parent == player or v.Parent == player.leaderstats) then
profile.Data[v.Name] = v.Value
end
end
end
local function PlayerAdded(player)
local profile = GameProfileStore:LoadProfileAsync(
"Player_" .. player.UserId,
"ForceLoad"
)
if profile ~= nil then
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) == true then
Profiles[player] = profile
loadUserData(player, profile)
else
profile:Release()
end
else
player:Kick()
end
end
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(PlayerAdded)(player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = Profiles[player]
if profile ~= nil then
profile:Release()
end
end)
return Profiles
Im using profile service, and whenever i load into the game, no items pop up in my "Inventory"
folder in my player. does anyone know why? ive tried everything, and there are zero errors, too.