local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Template = require(ServerScriptService.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Template)
local ProfileService = require(ServerScriptService.Libs.ProfileService)
local ProfileStore = ProfileService.GetProfileStore("Production", Template)
local KICK_MESSAGE = "We are having an issue with sorting data. Please try again soon. If it isnt fixed after a while, feel free to DM me."
local function CreateLeaderstats(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local honey = Instance.new("NumberValue", leaderstats)
honey.Name = "Honey"
honey.Value = profile.Data.Clicks
local coins = Instance.new("NumberValue", leaderstats)
coins.Name = "Coins"
coins.Value = profile.Data.Coins
end
local function LoadProfile(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if not profile then
player:Kick(KICK_MESSAGE)
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick(KICK_MESSAGE)
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = profile
CreateLeaderstats()
else
profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn(LoadProfile, player)
end
Players.PlayerAdded:Connect(LoadProfile)
Players.PlayerRemoving:Connect(function(player)
local profile = Manager.Profiles[player]
if profile then
profile:Release()
end
end)