I have written two scripts for a data store, but what if I want to edit other people's data, how do I do that?
script 1
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("CashSaveSystem") game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder",player) leader.Name = "leaderstats" local Cash = Instance.new("IntValue",leader) Cash.Name = "LifeFormFound" Cash.Value = ds:GetAsync(player.UserId) or 0 ds:SetAsync(player.UserId, Cash.Value) Cash.Changed:connect(function() ds:SetAsync(player.UserId, Cash.Value) end) end) game.Players.PlayerRemoving:connect(function(player) ds:SetAsync(player.UserId, player.leaderstats.Cash.Value) end)
script 2
local DataStore = game:GetService("DataStoreService") local ds2 = DataStore:GetDataStore("PointsSaveSystem") game.Players.PlayerAdded:connect(function(player) local leader = player.leaderstats local Points = Instance.new("IntValue",leader) Points.Name = "Rebirth" Points.Value = ds2:GetAsync(player.UserId) or 0 ds2:SetAsync(player.UserId, Points.Value) Points.Changed:connect(function() ds2:SetAsync(player.UserId, Points.Value) end) end) game.Players.PlayerRemoving:connect(function(player) ds2:SetAsync(player.UserId, player.leaderstats.Rebirth.Value) end)
can anyone help?
int64
. Make it a string to it can be something like "Player_1848495727285".local dataService = game:GetService("DataStoreService") local cashSave = dataService:GetDataStore("CashSaveSystem") local key game:GetService("Players").PlayerAdded:Connect(function(plr) -- Switch to :Connect, :connect is deprecated key = "Player_" .. plr.UserId local ls = Instance.new("Configuration") -- the parent argument to Instance.new is deprecated and is known to slow down performance, don't use ls.Name = "leaderstats" ls.Parent = plr local cash = Instance.new("IntValue") local data = cashSave:GetAsync(key) cash.Name = "Life Form Found" cash.Value = data[1] or 0 -- get data table, index the first item, cash value cash.Parent = 0 cash.Changed:Connect(function(value) cashSave:SetAsync(key, {value}) end) end) game:GetService("Players").PlayerRemoving:Connect(function(plr) cashSave:SetAsync( key, {plr.leaderstats["Life Form Found"].Value} ) end)