[ProfileService] Transferring Data to ProfileService

Transferring [Legacy] Data to ProfileService


Is it possible to transfer Data to the ProfileService without rollbacking everyone else data to the zero?

Legacy Script

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("PlayerStatistics")

ProfileService Script

local ProfileStore = ProfileService.GetProfileStore("PlayerStatistics", Template)

As you can see i’m using the same DataName (and the same player.UserId as the key in a function), so, how would i make to transfer everyone progress to the new system?

DataStore Editor Screenshots



As you can see, ProfileService does add a new scope, which is “Data”, while the Legacy one doesn’t add it, how can i move everyone progress to it?

2 Likes

Did you find out how to? I also want to do this and I dont know where to begin

1 Like

Hello, I had a similar problem today. I know I came late to the party, but this is how I did it:

Say you have an old DataStorage called PlayerData and you have decided to use ProfileService instead of your old method. What I did is I made a new DataStorage and called it PlayerDataV2 and made ProfileService use that one. Then in the DataTemplate of ProfileService, that you pass in ProfileService.GetProfileStore(), I have added a key called “DidDataTransfer” and set that equal to false. So whenever a player joins and has their profile loaded I would check if profile.Data.DidDataTransfer == false. If true, then get your old datastore and see if they have data in that datastore, then just transfer it to profile.Data.

local function OnPlayerAdded(player: Player)
	local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
	if profile ~= nil then
		profile:AddUserId(player.UserId)
		profile:Reconcile()
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick()
		end)
		if player:IsDescendantOf(Players) == true then
			Profiles[player] = profile
		else
			profile:Release()
		end
	else
		player:Kick("Data couldn't be loaded. Try again later.") 
		return
	end

	local data = profile.Data
	
	if not data.DidDataTransfer then
		local oldData = game:GetService("DataStoreService"):GetDataStore("Players"):GetAsync("Player_" .. player.UserId)
		if oldData then
			for i,v in oldData do
				profile.Data[i] = v
			end
		end
		data.DidDataTransfer = true
	end
end
8 Likes

Quite sure this would work:

Make sure to replace “PlayerStatistics” with the appropriate name for your data store and profile store. Also, ensure that the placeholders (-- Value for ... ) in the transferData function are replaced with the actual values fetched from the legacy DataStore for each player.

This script should fetch data from the legacy DataStore for each player and transfer it to the ProfileService without affecting other players’ data.

Summary
local dataStoreService = game:GetService("DataStoreService")
local legacyDataStore = dataStoreService:GetDataStore("PlayerStatistics")

local ProfileService = require(game.ServerScriptService:WaitForChild("ProfileService"))
local ProfileStore = ProfileService.GetProfileStore("PlayerStatistics", Template)

local function fetchData(player)
    local success, data = pcall(function()
        return legacyDataStore:GetAsync(tostring(player.UserId))
    end)
    
    if success then
        return data or {} -- Return the data or an empty table if it doesn't exist
    else
        warn("Failed to fetch data for player " .. player.Name .. ": " .. data)
        return {} -- Return an empty table in case of an error
    end
end

local function transferData(player)
    local profile = ProfileStore:LoadProfileAsync(tostring(player.UserId))
    
    if profile then
        local data = fetchData(player)
        profile.Data = {
            Agility = data.Agility or 0,
            Attack = data.Attack or 0,
            BoostX1 = data.BoostX1 or 0,
            BoostX2 = data.BoostX2 or 0,
            CurrentQuest = data.CurrentQuest or "",
            Defense = data.Defense or 0,
            Dragon1 = data.Dragon1 or "",
            Ki = data.Ki or 0,
            LOCK = data.LOCK or false
        }
        profile:Save()
        profile:Release()
    end
end

for _, player in ipairs(game.Players:GetPlayers()) do
    transferData(player)
end

This is exactly the same method i did to make it work

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