Advertisement
Alexplazz

Untitled

Nov 28th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. --// Services
  2. local DataService = {}
  3. local ServerStorage = game:GetService("ServerStorage")
  4. local ProfileService = require(ServerStorage.ProfileService)
  5.  
  6. --// Globals
  7. local DefaultData = {
  8.     Coins = 0;
  9.     Inventory = {};
  10. }
  11. local ProfileStore = ProfileService.GetProfileStore("ProfileStore", DefaultData)
  12. DataService.LoadedProfiles = {}
  13.  
  14. --// Core
  15. function DataService.Welcome(Player)
  16.     print("Loaded Player")
  17. end
  18.  
  19. function DataService.HandleClient(Player)
  20.     local Profile = ProfileStore:LoadProfileAsync(tostring(Player.UserId))
  21.     if Profile then
  22.         Profile:AddUserId(Player.UserId)
  23.         Profile:Reconcile()
  24.        
  25.         Profile:ListenToRelease(function()
  26.             DataService.LoadedProfiles[Player] = nil
  27.         end)
  28.        
  29.         if Player:IsDescendantOf(game.Players) then
  30.             DataService.LoadedProfiles[Player] = Profile
  31.             DataService.Welcome(Player)
  32.         else
  33.             Profile:Release()
  34.         end
  35.     else
  36.         Player:Kick("Data failed to load!")
  37.     end
  38. end
  39.  
  40. function DataService.HandleRemovingClient(Player)
  41.     local Profile = DataService.LoadedProfiles[Player]
  42.     if Profile then
  43.         Profile:Release()
  44.     end
  45. end
  46.  
  47.  
  48. return DataService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement