I want to be able to exit my game and re-enter it and have the same tool I left with, I also want all of my tools in a folder that my player owns in the future to be saved to as I will be making an inventory system soon.
Whole Idea: Have gun, leave game, enter game again, gun is saved.
DataManager Module Script:
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local modules = ServerScriptService:WaitForChild("Modules")
local ProfileService = require(modules:WaitForChild("ProfileService"))
local Template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))
local DataKey = "_DataStore"
local profileStore = ProfileService.GetProfileStore(DataKey, Template)
local datamanager = {}
datamanager.Profiles = {}
local function PlayerAdded(player: Player)
local profile = profileStore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
datamanager.Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then
datamanager.Profiles[player] = profile
leaderstats:Create(player, profile)
else
profile:Release()
end
else
player:Kick()
end
end
local function PlayerRemoving(player: Player)
local profile = datamanager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
return datamanager
Template Module Script:
local Template = {
Neon = 0,
Weapons = {},
}
return Template