local ProfileService = require(script:WaitForChild('ProfileService'))
local ProfileTemplate = {
Cash = 0;
Items = {};
}
local ProfileStore = ProfileService.GetProfileStore(
"PlayerData",
ProfileTemplate
)
local Profiles = {} -- [player] = profile
local function playerAdded(player)
local profile = ProfileService:LoadProfileAsync("Player_"..player.UserId)
if profile then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(game.Players) == true then
Profiles[player] = profile
else
profile:Release()
end
else
player:Kick()
end
end
-- when player joins
game.Players.PlayerAdded:Connect(function(player)
playerAdded(player)
local profile = Profiles[player]
if not profile then warn('No profile!') return end
local folder = Instance.new('Folder')
folder.Name = 'leaderstats'
folder.Parent = player
local cash = Instance.new('IntValue')
cash.Name = 'Cash'
cash.Value = profile.Data.Cash or 0
cash.Parent = folder
cash:GetPropertyChangedSignal('Value'):Connect(function()
profile.Data.Cash = cash.Value
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local profile = Profiles[player]
if profile then
profile:Release()
end
end)
for _, player in game.Players:GetPlayers() do
task.spawn(playerAdded, player)
end```
#leaderstat bug
1 messages · Page 1 of 1 (latest)
doesnt work
it doesnt make the folder and ChatGPT says it isnt running the game.Player.Playeradded block
i could be wrong but if its a leaderstats why are you not using data stores?
profile service is datastore
why dont you create the leaderstats folder and the stats inside the playerAdded function only after the profile has been successfully loaded and assigned?
i have a dev helping