Hello!
I am currently working on putting profile service into my game. Whenever I join the game my leaderstats won’t show. I looked at the output and there are no errors showing. API services are on and it prints in the output that the data will save, even though there is no leaderstats in. What could I do?
Here are all my scripts I am using:
Data Manager:
local dataManager = {}
dataManager.Profiles = {}
local players = game:GetService("Players")
local serverscriptservice = game:GetService("ServerScriptService")
local modules = serverscriptservice:WaitForChild("leaderboardModules")
local profileservice = require(modules:WaitForChild("ProfileService"))
local template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))
local dataKey = "_DataStore"
local profilestore = profileservice.GetProfileStore(dataKey, template)
local function playerAdded(player : Player)
local profile = profilestore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
dataManager.Profiles[player] = nil
player:Kick("Please rejoin the game, your data did not load.")
end)
if player:IsAncestorOf(players) then
dataManager.Profiles[player] = profile
leaderstats:Create(player, profile)
else
profile:Release()
end
else
player:Kick("Please rejoin the game, your data did not load.")
end
end
local function playerRemoving(player: Player)
local profile = dataManager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end
for _, player in players:GetPlayers() do
task.spawn(playerAdded, player)
end
players.PlayerAdded:Connect(playerAdded)
players.PlayerRemoving:Connect(playerRemoving)
return dataManager
Leaderstats Script:
local module = {}
function module:Create(player: Player, profile)
print("Hey!")
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = profile.Data.Coins
Coins.Parent = leaderstats
end
return module
Template Script:
local template = {
Coins = 0,
}
return template
Player Data Script:
require(script.Parent:WaitForChild("leaderboardModules"):WaitForChild("DataManager"))
Thank you so much for your time,