Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ProfileTemplate = {
- -- data template
- }
- local ProfileService = require(script.ProfileService)
- local Players = game:GetService("Players")
- local repStor = game:GetService("ReplicatedStorage")
- local ServerStorage = game:GetService("ServerStorage")
- local GameProfileStore = ProfileService.GetProfileStore(
- "PlayerData",
- ProfileTemplate
- )
- local cachedProfiles = {}
- local function PlayerDataLoader(player, profile)
- -- Load profile here, leaderstats, etc.
- end
- local function PlayerAdded(player)
- local profile = GameProfileStore:LoadProfileAsync(
- "Player_" .. player.UserId,
- "ForceLoad"
- )
- if profile ~= nil then
- profile:ListenToRelease(function()
- cachedProfiles[player] = nil
- player:Kick()
- end)
- if player:IsDescendantOf(Players) == true then
- cachedProfiles[player] = profile
- PlayerDataLoader(player, profile)
- else
- profile:Release()
- end
- else
- player:Kick()
- end
- end
- for _, player in ipairs(Players:GetPlayers()) do
- spawn(function()
- PlayerAdded(player)
- end)
- end
- Players.PlayerAdded:Connect(PlayerAdded)
- Players.PlayerRemoving:Connect(function(player)
- local profile = cachedProfiles[player]
- if profile ~= nil then
- profile:Release()
- end
- end)
- return cachedProfiles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement