#profile store
1 messages · Page 1 of 1 (latest)
send code ?
idk how i would do that
its like 4 diff scripts
“ProfileStore” by loleris (Successor module to ProfileService) [GitHub repo] ProfileStore is a Roblox DataStore wrapper that streamlines auto-saving, session locking and a few other features for the game developer. ProfileStore’s source code runs on a single ModuleScript. Read documentation here: ProfileStore wiki (Click me) Get the m...
its using this thing
local DataManager = require(game.ServerScriptService.Data.DataManager)
local Players = game:GetService("Players")
local Inventories = {}
local function UpdateInventoryData(player: Player)
local playerInventory = {}
Inventories[player.Name] = playerInventory
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local function GetInventory()
local profile = DataManager.Profiles[player]
table.clear(playerInventory)
for _, item in ipairs(character:GetChildren()) do
if item:IsA("Tool") then
table.insert(playerInventory, item.Name)
end
end
for _, item in ipairs(backpack:GetChildren()) do
if item:IsA("Tool") then
table.insert(playerInventory, item.Name)
end
end
if profile then
local profileInventory = profile.Data.Inventory
if profileInventory then
print("profile inventory data found")
profileInventory = playerInventory
for i, item in profileInventory do
print(item)
end
end
end
end
-- Initial scan
GetInventory()
-- Listen for changes
character.ChildAdded:Connect(GetInventory)
character.ChildRemoved:Connect(GetInventory)
backpack.ChildAdded:Connect(GetInventory)
backpack.ChildRemoved:Connect(GetInventory)
end
Players.PlayerAdded:Connect(function(player)
UpdateInventoryData(player)
end)
Players.PlayerRemoving:Connect(function(player)
task.wait(3)
Inventories[player.Name] = nil
end)
while true do
task.wait(5)
print(Inventories)
end```
local StatInfoModule = require(game.ReplicatedStorage.Modules.StatInfoModule)
local DataManager = {}
-- Stores profiles from profile store
DataManager.Profiles = {}
function DataManager.SeeProfiles()
print(DataManager.Profiles)
end
function DataManager.SeeProfile(player)
print(DataManager.Profiles[player])
end
function DataManager.GetProfile(player)
local profile = DataManager.Profiles[player]
return profile
end
function DataManager.AddCash(player: Player, amount: number) -- use negative values to subract cash
local profile = DataManager.Profiles[player]
if not profile then
return
end
profile.Data.Cash += amount
player.leaderstats.Cash.Value = profile.Data.Cash
StatInfoModule.UpdateStats(player)
end
function DataManager.AddRebirth(player:Player, amount:number)
local profile = DataManager.Profiles[player]
if not profile then
return
end
profile.Data.Rebirths += amount
player.leaderstats.Rebirths.Value = profile.Data.Rebirths
end
return DataManager
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ServerScriptService = game:GetService("ServerScriptService")
-- ProfileStore
local ProfileStore = require(ServerScriptService.Libraries.ProfileStore)
local function GetStoreName()
return RunService:IsStudio() and "Test" or "Live"
end
local Template = require(ServerScriptService.Data.Template)
local DataManager = require(ServerScriptService.Data.DataManager)
-- Access profile store
local PlayerStore = ProfileStore.New(GetStoreName(), Template)
-- Add leaderstats and synchronize player data (Can do other things that you want to occur on player join)
local function Initialize(player: Player, profile: typeof(PlayerStore:StartSessionAsync()))
print("Initializing")
-- leaderstats
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
cash.Value = profile.Data.Cash
local rebirths = Instance.new("IntValue", leaderstats)
rebirths.Name = "Rebirths"
rebirths.Value = profile.Data.Rebirths
-- inventory
local inventory
inventory = profile.Data.Inventory
if inventory then
print("inventory exists")
for i, item in inventory do
print(item)
end
for i, item in ipairs(inventory) do
local clonedItem = game.ReplicatedStorage.Items:FindFirstChild(item):Clone()
clonedItem.Parent = player.Backpack
end
end
end
-- Creates and stores a profile
local function PlayerAdded(player: Player)
-- Start new profile session
local profile = PlayerStore:StartSessionAsync("Player_"..player.UserId, {
Cancel = function()
return player.Parent ~= Players
end,
})
-- Sanity check to ensure profile exists
if profile ~= nil then
profile:AddUserId(player.UserId) -- GDPR compliance
profile:Reconcile() -- Fill in missing data variables from template
-- Handles session-locking
profile.OnSessionEnd:Connect(function()
DataManager.Profiles[player] = nil
player:Kick("Data error occurred. Please rejoin." )
end)
-- Save profile for later use/access
if player.Parent == Players then
DataManager.Profiles[player] = profile
Initialize(player, profile)
else
profile:EndSession()
end
else
-- Server shuts down while player is joining
player:Kick("Data error occurred. Please rejoin.")
end
end
-- Handle early joiners
for i, player in Players:GetPlayers() do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
local profile: typeof(PlayerStore:StartSessionAsync()) = DataManager.Profiles[player]
if not profile then
return
end
profile:EndSession()
for i, item in ipairs(profile.Data.Inventory) do
print(item)
end
end)
if success then
print("data saved successfully for "..player.Name)
DataManager.Profiles[player] = nil
end
if err then
warn("Error: "..err)
end
end)
wait(5)
DataManager.SeeProfiles()
@thorn saffron
so do you even understand this code at all
ye
like
in studio
it saves the inventory just fine when player leaves
and it gives them their tools back when they join
but it doesnt in the actual roblox game
does it print anything
ye
what does it print
wait in studio or game
studio and game
lemme check game
try adding a task.wait(5) before the --inventory
and check what happen in game
wdym --inventory
ohh