So I made a ProfileService in my game and it won’t fire. I made a module script in ServerScriptService and the ProfileService Module is in the leaderstats module I made. Here is my full script:
local Players = game:GetService("Players")
local MareketPlaceService = game:GetService("MarketplaceService")
local cachedProfiles = {}
local ProfileService = require(game.ServerScriptService.Leaderstats.ProfileService)
local saveStructure = {
BattleCoins = 0;
Deaths = 0;
Kills = 0;
playTime = 0;
Wins = 0;
Level = 0;
XP = 0;
}
local PlayerProfileService = ProfileService.GetProfileStore("PlayerData", saveStructure)
local function playerDataLoaded(player)
local profile = cachedProfiles[player]
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local BattleCoins = Instance.new("IntValue")
BattleCoins.Name = "Battle Coins"
BattleCoins.Value = profile.Data.BattleCoins
BattleCoins.Parent = folder
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = profile.Data.Deaths
deaths.Parent = folder
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = profile.Data.Kills
kills.Parent = folder
local playtime = Instance.new("IntValue")
playtime.Name = "playTime"
playtime.Value = profile.Data.playTime
playtime.Parent = folder
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = profile.Data.Wins
wins.Parent = folder
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Value = profile.Data.Level
Level.Parent = folder
local RequiredXP = Instance.new("IntValue")
RequiredXP.Name = "RequiredXP"
RequiredXP.Value = Level.Value * 1000
RequiredXP.Parent = folder
local XP = Instance.new("IntValue")
XP.Name = "XP"
XP.Value = profile.Data.XP
XP.Parent = folder
local RoundKills = Instance.new("IntValue")
RoundKills.Name = "RoundKills"
RoundKills.Value = 0
RoundKills.Parent = player
local ServerAgeForPlayer = Instance.new("IntValue")
ServerAgeForPlayer.Name = "PlayerServerAge"
ServerAgeForPlayer.Parent = folder
local MaxLevelReached = Instance.new("BoolValue")
MaxLevelReached.Name = "MaxLevelReached"
MaxLevelReached.Parent = player
local EquippedTrail = Instance.new("StringValue")
EquippedTrail.Name = "EquippedTrail"
EquippedTrail.Parent = player
EquippedTrail.Value = "None"
local RequestedTrailPurchase = Instance.new("StringValue")
RequestedTrailPurchase.Name = "RequestedTrailPurchase"
RequestedTrailPurchase.Parent = player
RequestedTrailPurchase.Value = "None"
local EquippedTexture = Instance.new("StringValue")
EquippedTexture.Name = "EquippedTexture"
EquippedTexture.Parent = player
EquippedTexture.Value = "None"
local RewardValue = Instance.new("IntValue")
RewardValue.Name = "RewardValue"
RewardValue.Parent = player
RewardValue.Value = 0
local Serverkills = Instance.new("IntValue")
Serverkills.Name = "ServerKills"
Serverkills.Value = 0
Serverkills.Parent = player
spawn(function()
while true do
if profile ~= nil then
BattleCoins.Value = profile.Data.BattleCoins
deaths.Value = profile.Data.Deaths
kills.Value = profile.Data.Kills
playtime.Value = profile.Data.playTime
wins.Value = profile.Data.Wins
Level.Value = profile.Data.Level
XP.Value = profile.Data.XP
else
break
end
wait(.1)
end
end)
print(player.Name .. "'s data is loaded.")
if Level.Value == 0 then
profile.Data.Level = 1
Level.Value = profile.Data.Level
RequiredXP.Value = Level.Value * 100
print(player.Name.." Started they're level system.")
else
-- already has data
end
if Level.Value == 1000 then
MaxLevelReached.Value = true
end
XP:GetPropertyChangedSignal("Value"):Connect(function(Changed)
if player:FindFirstChild("leaderstats"):FindFirstChild("PlayerServerAge").Value <= 15 then
print("Can't change they're XP at this moment.")
elseif XP.Value >= RequiredXP.Value then
-- ProfileService Part
profile.Data.XP = 0
profile.Data.Level += 1
-- Leaderstats Part
XP.Value = profile.Data.XP
Level.Value = profile.Data.Level
RequiredXP.Value = Level.Value * 100
end
end)
while true do
wait(1)
profile.Data.playTime += 1
player:FindFirstChild("leaderstats"):FindFirstChild("playTime").Value = profile.Data.playTime
player:FindFirstChild("leaderstats"):FindFirstChild("PlayerServerAge").Value += 1
end
end
local function PlayerAdded(player)
local profile = PlayerProfileService:LoadProfileAsync("Player_" ..player.UserId, "ForceLoad")
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick("Your data loaded Remotly, please rejoin.")
end)
if player:IsDescendantOf(Players) then
cachedProfiles[player] = profile
playerDataLoaded(player)
else
profile:Release()
end
else
player:Kick("Data did not load, please rejoin or report in the links below of game Description.")
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
My leaderstats are not in the player, and the ProfileService Module did not print anything. How can I fix this? I also have API Services enabled.
Sincerely,