Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you edit a data store for players?

Asked by 5 years ago

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?

1
Try this plugin, I haven't used it but I've heard it's nice. https://www.roblox.com/library/701506235/DataStore-Editor climethestair 1663 — 5y
0
I have this plugin but I don't know how to use it! soooo RainbowBeastYT 85 — 5y
0
it has a tutorial in it SulaymanArafat 230 — 5y
0
well in the description SulaymanArafat 230 — 5y
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 Impacthills 223 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
but how about the rebirth script? I have a rebirth leaderstats too RainbowBeastYT 85 — 5y
0
Do the same User#19524 175 — 5y
0
Within the same script User#19524 175 — 5y
Ad

Answer this question