#Profile store not working

1 messages · Page 1 of 1 (latest)

rich yarrow
#

Im not sure if I am not using this properly but please somebody help me!

local ProfileStore = require(game.ServerScriptService.ProfileStore)

local PROFILE_TEMPLATE = {
    Money = 0,
    Items = {},
}

local players = game:GetService("Players")

local playerstore = ProfileStore.New("playerstore", PROFILE_TEMPLATE)
local Profiles: {[Player]: typeof(playerstore:StartSessionAsync())} = {}

local function plrAdded(plr)
    
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Parent = leaderstats
    

    local profile = playerstore:StartSessionAsync(`{plr.UserId}`, {
        Cancel = function()
            return plr.Parent ~= players
        end,
    })

    if profile ~= nil then

        profile:AddUserId(plr.UserId) 
        profile:Reconcile()

        if plr.Parent == players then
            Profiles[plr] = profile
            print(`Profile loaded for {plr.DisplayName}!`)
            money.Value = profile.Data.Money

            money:GetPropertyChangedSignal("Value"):Connect(function()
                profile.Data.Money = money.Value
            end)
        else
            profile:EndSession()
        end
    end

end

for _, plr in players:GetPlayers() do
    task.spawn(plrAdded, plr)
end

players.PlayerAdded:Connect(plrAdded)

players.PlayerRemoving:Connect(function(plr)
    local profile = Profiles[plr]
    if profile ~= nil then
        profile:EndSession()
    end
end)

game:BindToClose(function()
    for _, plr in players:GetPlayers() do
            local profile = Profiles[plr]
            if profile ~= nil then
                profile:EndSession()
        end
    end
end)



olive sparrow
#

looks good

#

just try making a datamanager module

#

that was the way to handle data

#

theres a vid on yt

#

for profile store aswell

rich yarrow
olive sparrow
#

u ended the session or not

#

when the plr died

#

otherwise idk

lapis fog
#

And if your modifying it on the server I hope your not just changing the leader stat and hoping that makes it save