Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you edit a data store for players?

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?

5 comments

1

Try this plugin, I haven't used it but I've heard it's nice. https://www.roblox.com/library/701506235/DataStore-Editor

0

I have this plugin but I don't know how to use it! soooo

0

it has a tutorial in it

0

well in the description

0

You should implement a custom command then you could just run the logic with a command in the console like 'editdata playerUserName key new value

1 answer

###The key for data stores needs to be a string, and you assigned it an 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)

###May not answer your questions but I fixed your code up a bit.

3 comments

0

but how about the rebirth script? I have a rebirth leaderstats too

0

Do the same

0

Within the same script

This discussion is preserved as it was. New answers, comments, and votes are closed.