Help with obby datastore

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)

I recommend watching this

Credit : Wheez

Is this help for you?

  • Yes, Thank you
  • No, It didn’t

0 voters

thanks but i was hoping someone would just explain how i could do it instead of giving me a free model

what exactly is your problem? is there an error?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.