I just transfer last day to Profile Service but the value is constantly changing to 0 can someone help me.
local Players = game:GetService("Players")
local cachedProfiles = {}
local ProfileService = require(script.ProfileService)
local saveStructure = {
Coins = 0;
Wins = 0;
Levels = 0;
Exp = 0;
}
local PlayerProfileStore = ProfileService.GetProfileStore("PlayerSaveData", saveStructure)
local function PlayerDataLoaded(player)
local profile = cachedProfiles[player]
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstatss"
leaderstats.Parent = player
local leaderwin = Instance.new("Folder")
leaderwin.Name = "leaderwins"
leaderwin.Parent = player
local leaderlev = Instance.new("Folder")
leaderlev.Name = "leaderlevels"
leaderlev.Parent = player
-- Handler For Coins
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = profile.Data.Coins
Coins.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = profile.Data.Wins
Wins.Parent = leaderwin
local Levels = Instance.new("IntValue")
Levels.Name = "Levels"
Levels.Value = profile.Data.Levels
Levels.Parent = leaderlev
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
Exp.Value = profile.Data.Exp
Exp.Parent = leaderlev
spawn(function()
while true do
local profile = cachedProfiles[player]
if profile ~= nil then
Coins.Value = profile.Data.Coins
Wins.Value = profile.Data.Wins
Levels.Value = profile.Data.Levels
Exp.Value = profile.Data.Exp
else
break
end
wait(0.1)
end
end)
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)
else
profile:Release()
end
else
player:Kick("Unable to load saved data. 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