Update:
Added 2 methods to wait for a profile.
Added this because I noticed if you try to get their profile right when they join, it doesnβt register it.
Example:
--!strict
local ReplicatedStorage = game:GetService('ReplicatedStorage')
--> util
local util = require(ReplicatedStorage.Utility)
local PlayerUtil = util.PlayerUtil
--> refs
local ProfileStores = require(script.Parent.ProfileStores)
local PlayerData = ProfileStores.PlayerData
--> Method 1
PlayerUtil.PlayerAdded(function(player : Player)
local profile = PlayerData:WaitForProfile(player)
local leaderstats = Instance.new('Folder')
local Streak = Instance.new('NumberValue')
local Level = Instance.new('NumberValue')
leaderstats.Name = 'leaderstats'
Streak.Name = 'Streak'
Level.Name = 'Level'
Streak.Parent = leaderstats
Level.Parent = leaderstats
leaderstats.Parent = player
Streak.Value = profile.Data.Stats.Streak
Level.Value = profile.Data.Level
end)
--> Method 2
PlayerData.ProfileLoaded:Connect(function(player : Player, profile)
local leaderstats = Instance.new('Folder')
local Streak = Instance.new('NumberValue')
local Level = Instance.new('NumberValue')
leaderstats.Name = 'leaderstats'
Streak.Name = 'Streak'
Level.Name = 'Level'
Streak.Parent = leaderstats
Level.Parent = leaderstats
leaderstats.Parent = player
Streak.Value = profile.Data.Stats.Streak
Level.Value = profile.Data.Level
end)
return nil
Update:
Added profile mocking for studio.
Added leaderstats.
Example:
--> Mocking:
PlayerData.new('Test_Data_0', {}, false) --> Will not save in studio
PlayerData.new('Test_Data_1', {}) --> Will not save in studio
PlayerData.new('Test_Data_2', {}, true) --> Will save in studio
--> leaderstats
local Profiles = PlayerData.new('Test_Store_0', {
Stats = {
Level = 1,
Streak = 0,
},
Coins = 500
}, false, {
['Level'] = 'Stats/Level', --> Name = Path in data table.
['Streak'] = 'Stats/Streak'
})
Profiles:UpdateLeaderstats(player) --> will update the leaderstats with the updated profile values.