Wiping Players Data | Profile Service

How do I wipe a players data using :WipeProfileAsync()
What is the ProfileStore and Profile Key?

image

.
Here’s my code: tell me what is what? :>

local profileService = require(script.ProfileService)
local requestData = script.Parent.RequestData
local requestSave = script.Parent.RequestSave

local dataStoreServer = {}

local dataTemplate = require(script.Parent.Template)
local leaderstats = require(script.Parent.Leaderstats)

local playerData = profileService.GetProfileStore(
	"TestData",
	dataTemplate
)

local profiles = {}

local function playerAdded(player)
	local profile = playerData:LoadProfileAsync("player_"..player.UserId)
	if profile then
		profile:AddUserId(player.UserId)
		profile:Reconcile()

		profile:ListenToRelease(function()
			profiles[player] = nil

			player:Kick("Joined on another server")
		end)

		if player:IsDescendantOf(game.Players) then
			profiles[player] = profile
			local dataLoaded = Instance.new("BoolValue", player)
			dataLoaded.Name = "DataLoaded"
			dataLoaded.Value = true
		else
			profile:Release()
		end
	else
		player:Kick("Unknown data error.")
	end
end

local function getProfile(player: Player)
	assert(profiles[player], "Profile does not exist for: "..player.UserId)

	return profiles[player]
end

function dataStoreServer:Wipe(Player: Player, Key: string)
	local profile = getProfile(Player)
	
	profiles:WipeProfileAsync(profile)
end

function dataStoreServer:Get(player: Player, key: string)
	local profile = getProfile(player)
	if profile.Data[key] == nil then
		warn("Data does not exist for key: "..key)
	end

	return profile.Data[key]
end

function dataStoreServer:Set(player: Player, key: string, value: any)
	local profile = getProfile(player)
	if profile.Data[key] == nil then
		warn("Data does not exist for key: "..key)
	end

	profile.Data[key] = value
end

function dataStoreServer:Update(player: Player, key: string, callback)
	local profile = getProfile(player)

	local oldData = self:Get(player, key)
	local newData = callback(oldData)

	self:Set(player, key, newData)
end

for _, player in pairs(game:GetService("Players"):GetPlayers()) do
	task.spawn(playerAdded, player)
end

game.Players.PlayerAdded:Connect(playerAdded)

game.Players.PlayerRemoving:Connect(function(player)
	local profile = profiles[player]
	if profile then
		
		for lname, kname in pairs(leaderstats) do
			profile.Data[kname] = player.leaderstats[lname].Value
		end
		
		profile:Release()
	end
end)

requestData.OnServerInvoke = function(player, key)
	return dataStoreServer:Get(player, key)
end

requestSave.OnServerInvoke = function(player, key: string, value)
	if dataTemplate[key] and key:sub(1, 6) == "Client" then
		dataStoreServer:Set(player, key, value)
		return true
	end
	
	return false
end

return dataStoreServer
1 Like

This post here may be of help to you:

2 Likes