How to change datastore script without deleting the users data

I’ve changed the “player.Name” to “player.UserId” But it seems that the users data is gone, how can I Fix that?

[Found this script on youtube]

--[[Savin'
		Dem
			Stats	
--]]
game.Players.PlayerRemoving:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i =  1, #statstorage do
	datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
	print("saved data number "..i)
	
end
print("Stats successfully saved")	
end)


--[[
	Loadin'
		Dem
			Stats
--]]
game.Players.PlayerAdded:connect(function(player)
		local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
	
	player:WaitForChild("leaderstats")
	wait(1)
	local stats = player:FindFirstChild("leaderstats"):GetChildren()
	for i = 1, #stats do			
	stats[i].Value = datastore:GetAsync(stats[i].Name)
	print("stat numba "..i.." has been found")
		end
end)
1 Like

i had to transfer data stores aswell and i did

local Ds = game:GetService('DataStoreService')

local NewDs = Ds:GetDataStore('ID'
local OldDs = Ds:GetDataStore('Name')

game.Players.PlayerAdded:Connect(function(player)
     local ITems

    local success,errormsg = pcall(function()
       ITems =  OldDs:GetAsync(player.Name)
    end)

    if success then
        if ITems then
            NewDs:SetAsync(player.Userid,ITems)
        end
    else
       print(errormsg)
    end
end)
2 Likes

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