Advertisement
Guest User

Untitled

a guest
Jun 10th, 2021
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local ProfileTemplate = {
  2.                             -- data template
  3.                             }
  4.  
  5. local ProfileService = require(script.ProfileService)
  6.  
  7. local Players = game:GetService("Players")
  8. local repStor = game:GetService("ReplicatedStorage")
  9. local ServerStorage = game:GetService("ServerStorage")
  10.  
  11. local GameProfileStore = ProfileService.GetProfileStore(
  12.     "PlayerData",
  13.     ProfileTemplate
  14. )
  15.  
  16. local cachedProfiles = {}
  17.  
  18. local function PlayerDataLoader(player, profile)
  19.     -- Load profile here, leaderstats, etc.
  20. end
  21.  
  22. local function PlayerAdded(player)
  23.     local profile = GameProfileStore:LoadProfileAsync(
  24.         "Player_" .. player.UserId,
  25.         "ForceLoad"
  26.     )
  27.     if profile ~= nil then
  28.         profile:ListenToRelease(function()
  29.             cachedProfiles[player] = nil
  30.             player:Kick()
  31.         end)
  32.         if player:IsDescendantOf(Players) == true then
  33.             cachedProfiles[player] = profile
  34.             PlayerDataLoader(player, profile)
  35.         else
  36.             profile:Release()
  37.         end
  38.     else
  39.         player:Kick()
  40.     end
  41. end
  42.  
  43. for _, player in ipairs(Players:GetPlayers()) do
  44.     spawn(function()
  45.                         PlayerAdded(player)
  46.                     end)
  47. end
  48.  
  49. Players.PlayerAdded:Connect(PlayerAdded)
  50.  
  51. Players.PlayerRemoving:Connect(function(player)
  52.     local profile = cachedProfiles[player]
  53.     if profile ~= nil then
  54.         profile:Release()
  55.     end
  56. end)
  57.  
  58. return cachedProfiles
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement