I’m trying to use profileservice to save intvalues linked to player but they won’t “save” even though it prints “saved”, because when I start a new playtest session all of my values reset to 0.
local Players = game:GetService("Players")
local cachedProfiles = {}
local ProfileService = require(script.ProfileService)
local saveStructure = {
TIX = 0;
__NOTEXTURES = 0;
}
local PlayerProfileStore = ProfileService.GetProfileStore("PlayerSaveData", saveStructure)
local function PlayerDataLoaded(player)
local profile = cachedProfiles[player]
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local TIX = Instance.new("IntValue")
TIX.Name = "TIX"
TIX.Value = profile.Data.TIX
TIX.Parent = folder
local __MISC = Instance.new("Folder")
__MISC.Name = "__SETTINGS"
__MISC.Parent = player
local __NOTEXTURES = Instance.new("IntValue")
__NOTEXTURES.Name = "__REDUCETEXTURES"
__NOTEXTURES.Value = profile.Data.__NOTEXTURES
local profile = cachedProfiles[player]
if profile ~= nil then
__NOTEXTURES.Value = profile.Data.__NOTEXTURES
TIX.Value = profile.Data.TIX
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
task.spawn(function()
PlayerAdded(player)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = cachedProfiles[player]
if profile ~= nil then
print("saved")
profile:Release()
end
end)
return cachedProfiles