I’m trying to achieve a working and optimized inventory.
unfortunately I just recently started using profileservices to store data so I still have a lot to learn.
in the line:
21,22,23>> StarterPlayerScripts.Client.PetInventory
Pets.ChildAdded:Connect(function()
UpdateInv()
end)
This would work in a normal DataStore system but unfortunately because profile services stores the data elsewhere this line doesn’t work.
I tought of 2 main solutions but i don’t know how to do any of them:
Either update the PetsFolder Function in DataHandler Script to make it so it checks the data every second and updates the folder[UNOPTIMIZED?]:
local function PetsFolder(player)
local profile = Profiles.Profiles[player]
if not profile then return end
local PetsFolder = Instance.new("Folder", player)
PetsFolder.Name = "Pets"
for i, v in pairs(profile.Data.Pets) do
local Pet = Instance.new("BoolValue", PetsFolder)
Pet.Name = v
end
end
local function PlayerAdded(player)
local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId) -- GDPR compliance
profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
profile:ListenToRelease(function()
Profiles.Profiles[player] = nil
-- The profile could've been loaded on another Roblox server:
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
end)
if player:IsDescendantOf(Players) == true then
Profiles.Profiles[player] = profile
-- A profile has been successfully loaded:
GiveLeaderstats(player)
PetsFolder(player)
else
-- Player left before the profile loaded:
profile:Release()
end
else
-- The profile couldn't be loaded possibly due to other
-- Roblox servers trying to load this profile at the same time:
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
end
end
Or Change the PlayerInventory script.
local Player = game.Players.LocalPlayer
local Pets = Player:WaitForChild("Pets")
local ReplicatedStorage = game.ReplicatedStorage
local ProfileManager = require(game:GetService("ServerScriptService").PlayerData.ProfileManager)
local UI = Player:WaitForChild("PlayerGui"):WaitForChild("Inventory")
local function UpdateInv()
for i, v in pairs(Pets:GetChildren()) do
if UI.Frame.Main.Pets:FindFirstChild(v.Name) then
else
local T = script.Template:Clone()
T.Parent = UI.Frame.Main.Pets
T.Name = v.Name
end
end
end
UpdateInv()
Pets.ChildAdded:Connect(function()
UpdateInv()
end)
Thank you for reading.