So I finally moved to Profile Service to save Data in my game. But I’m trying to figure out how to add to the players value without breaking the Data or players Data or players Value, etc. Here is what I was testing:
local ProfileService = require(game.ServerScriptService.Leaderstats)
game.Players.PlayerAdded:Connect(function(player)
local getPlayerData = ProfileService[player]
while true do
wait(5)
getPlayerData.Data.Points += 100
end
end)
And it gave me this error:
And line 7 is this: getPlayerData.Data.Points += 100
If you need, here is the Module script that is used to handle the leaderstats. (The ProfileService Module is in the Leaderstast Module)
local Players = game:GetService("Players")
local cachedProfiles = {}
local ProfileService = require(script.ProfileService)
local saveStructure = {
Points = 0;
Rubys = 0;
Deaths = 0;
Kills = 0;
playTime = 0;
Wins = 0;
}
local PlayerProfileService = ProfileService.GetProfileStore("PlayerLeaderstats", saveStructure)
local function playerDataLoaded(player)
local profile = cachedProfiles[player]
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = profile.Data.Points
points.Parent = folder
local rubys = Instance.new("IntValue")
rubys.Name = "Rubys"
rubys.Value = profile.Data.Rubys
rubys.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 RoundKills = Instance.new("IntValue")
RoundKills.Name = "RoundKills"
RoundKills.Value = 0
RoundKills.Parent = player
spawn(function()
while true do
if profile ~= nil then
points.Value = profile.Data.Points
rubys.Value = profile.Data.Rubys
deaths.Value = profile.Data.Deaths
kills.Value = profile.Data.Kills
playtime.Value = profile.Data.playTime
wins.Value = profile.Data.Wins
else
break
end
wait(.1)
end
end)
print(player.Name .. "'s data is loaded.")
end
local function PlayerAdded(player)
local profile = PlayerProfileService:LoadProfileAsync("Player_" ..player.UserId, "ForceLoad")
if profile ~= nil then
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
Let me know a modern version since I got this script from July of 2020.
Thanks for your help,