I am using Profile Service and need help with saving the checkpoint and setting the hrp cframe to the checkpoint when the player dies/joins and save that
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Template = require(ServerScriptService.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)
local ProfileStore = ProfileService.GetProfileStore(
"Production",
Template
)
local function CreateLeaderstats(player: Player, profile)
local profile = Manager.Profiles[player]
if not profile then return end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Stage = Instance.new("NumberValue")
Stage.Name = "Stage"
Stage.Parent = leaderstats
Stage.Value = profile.Data.Stage
end
local KICK_MESSAGE = "Data issue, try rejoining"
local function LoadData(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick(KICK_MESSAGE)
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = profile
CreateLeaderstats(player)
else
profile:Release()
end
else
player:Kick(KICK_MESSAGE)
end
end
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(LoadData, player)
end
Players.PlayerAdded:Connect(LoadData)
Players.PlayerRemoving:Connect(function(player: Player)
local profile = Manager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end)