Hello guys! So I am using profile service for a game and for some reason the leaderstats does not appear and I don’t know why i don’t get any error
Here is the script:
local Players = game:GetService('Players')
local cachedProfiles = {}
local ProfileService = require(script.ProfileService)
local Savestrucure = {
Kills = 0;
Cash = 0;
X2MAGOWNED = false;
X2MAGUSING = false;
}
local PlayerProfileStore = ProfileService.GetProfileStore('PLayerData', Savestrucure)
local function PlayerDataLoaded(player)
local profile = cachedProfiles[player]
local folder = Instance.new('Folder')
folder.Name = 'leaderstats'
folder.Parent = player
local Kill = Instance.new('IntValue')
Kill.Name = 'Kills'
Kill.Value = profile.Data.Kills
Kill.Parent = folder
local Cash = Instance.new('IntValue')
Cash.Name = 'Cash'
Cash.Value = profile.Data.Cash
Cash.Parent = folder
spawn(function()
while true do
local profile = cachedProfiles[player]
if profile ~= nil then
Kill.Value = profile.Data.Kills
Cash.Value = profile.Data.Cash
end
wait(0.1)
end
end)
print(player.Name .. "'s data is loaded")
end
local function PlayerAdded(player)
local profile = PlayerProfileStore:LoadProfileAsync('Player_' .. player.UserId, 'ForceLoad')
if profile ~= nil then
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick('Your profile has been loaded remotely. Please rejoin.')
end)
if player:IsDescendantOf(Players) then
cachedProfiles[player] = profile
PlayerDataLoaded(player)
print(debug)
else
profile:Release()
end
else
player:Kick('Your data was not able please rejoin!')
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