What I’m trying to achieve: I’m trying to transfer a datastore to a new and improved data store script with the player data since the old datastore script was poorly made.
I made a post earlier about this but the responders weren’t helpful at all and didn’t reach back to me.
It would be greatly appreciated if someone helps me out.
old script
local MyDataStore = DataStoreService:GetDataStore('DATASTORES')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = 'leaderstats'
local currency = Instance.new("IntValue", leaderstats)
currency.Name = 'cash'
currency.Value = 0
local PlayerCashId = 'cash'..player.UserId
local CashData
local s, err = pcall(function()
CashData = MyDataStore:GetAsync(PlayerCashId)
end)
if s then
currency.Value = CashData
else
warn(err)
end
currency:GetPropertyChangedSignal("Value"):Connect(function()
currency.Value = math.clamp(currency.Value, 0, math.huge)
end)
end)
New
local DataStore = DataStoreService:GetDataStore('DATASTORES')
game.Players.PlayerAdded:Connect(function(player)
local currency = Instance.new("IntValue")
currency.Name = "cash"
currency.Value = 0
currency.Parent = player
local data = nil
local success, errorMsg = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if data ~= nil then
if data.cash then
currency.Value = data.cash
end
end
end)
local DataStore = DataStoreService:GetDataStore('DATASTORES')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = ‘leaderstats’
local currency = Instance.new("IntValue")
currency.Name = "cash"
currency.Value = 0
currency.Parent = leaderstats
local data = nil
local success, errorMsg = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if data ~= nil then
if data.cash then
currency.Value = data.cash
end
end
end)
the leaderstats is very necessary, when you want to make a leaderstats because if you don’t have it, the value won’t pop up in the leaderboard.
In the game I’m working on I have the leaderboard disabled so in that circumstances, I really don’t need it. The edit does work but It would be great if there’s some other way.