Hi! when i close all servers data previously saved loss, also if i make an update in PlayerData table how do i add it to other player’s, is there a way to “merge” old player data with new?? lets say i want to add more “wheelChairs” and i need to update a new “wheelChair” how do i add it to current player data so he can buy and save that new wheelchair in to his inventory?? I show my script called “Leaderboard” in server script service below:
local DataStore2 = require(game.ServerScriptService:WaitForChild(“DataStore2”)) – --require(etcetc)
–Cuando desee remover datos cambio la clave desde aca
local MainKey = “hereismainkey”
DataStore2.Combine(MainKey, “Lvl”, “Exp”, “Cash”, “Gems”, “Inventory”)
–if something is changed on this table
–change MainKey for something else
–to avoid problems.
–any starter player will get this table to hold current data.
local function CreateDataTable()
local PlayerData = {
Lvl = 1,
Exp = 0,
Cash = 0,
Gems = 0,
Inventory = {
--upgradeable items
[1] = {
--shops
-- each index [1] represents the
-- player inventory data related to a particular shop.
[1] = {
wheelChair = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
keyboard = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
healLaser = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
},
[2] = {
wheelChair = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
keyboard = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
healLaser = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
}
},
--current upgradeable item equipped
[2] = {
wheelChair = {shopLvl = 1, itemIndex = 1}, --when here i define wheelchair
keyboard = {shopLvl = 1, itemIndex = 1}, --keyboard
healLaser = {shopLvl = 1, itemIndex = 1} --healLaser
},
--normal item you can save pets/vehicles/clothes(hats/pants/jackets) here
[3] = {
pets = {},
vehicles = {},
clothes = {
hats = {},
shirts = {},
pants = {},
shoes = {}
}
},
--here we save favorite items
--using table.insert
[4] = {
--we sort by item name and favourite index
tools = {
},
vehicles = {
},
pets = {
},
clothes = {
}
}
}
}
return PlayerData -- Cuando la funcion es llamada retorna la tabla
end
game.Players.PlayerAdded:Connect(function(player)
local PlayerData = DataStore2(MainKey, player):Get(CreateDataTable()) --GetPlayersDataTable
--local leaderstats = Instance.new("IntValue", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
--Nivel
local Level = Instance.new("IntValue") --Creating a intvalue and parenting it to Leaderstats
Level.Name = "Level" --Name
--local cash = Instance.new("IntValue", leaderstats)
local cash = Instance.new("IntValue")
cash.Name = "Cash"
--Experiencia
local Gems = Instance.new("IntValue") --Creating a intvalue and parenting it to Leaderstats
Gems.Name = "Gems" --Name
local LvlData = DataStore2("Lvl", player)
local CashData = DataStore2("Cash", player)
local GemsData = DataStore2("Gems", player)
local inventoryData = DataStore2("Inventory", player)
--local inventory
--update leaderboard stats
local function UpdateAllStats(UpdatedStats)
Level.Value = DataStore2(MainKey, player):Get(UpdatedStats).Lvl
cash.Value = DataStore2(MainKey, player):Get(UpdatedStats).Cash
Gems.Value = DataStore2(MainKey, player):Get(UpdatedStats).Gems
--inventory = DataStore2(MainKey, player):Get(UpdatedStats)["Inventory"]
end
--player data
UpdateAllStats(PlayerData)
DataStore2(MainKey, player):OnUpdate(UpdateAllStats)
--save status in leaderstats
leaderstats.Parent = player
Level.Parent = leaderstats
cash.Parent = leaderstats
Gems.Parent = leaderstats
end)
thx i really apreaciatte your help.