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

Would there be an easier way to use DataStore for multiple Values?

I'm making a place that will save multiple values and I was wondering if I could use an easier way for values?

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder",player)
 folder.Name = "places"
 local stat = Instance.new("IntValue",folder)
 stat.Name = "first"
 stat.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, stat.Value)
 stat.Changed:connect(function()
  ds:SetAsync(player.UserId, stat.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.places.first.Value)
end)

2 comments

0

use an array to store all the values

0

do a for i,v in pairs on the values parent

1 answer

You can use an array to save all your data:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local d = ds:GetAsync(player.UserId)
 local folder = Instance.new("Folder",player)
 folder.Name = "places"
 local stat = Instance.new("IntValue",folder)
 stat.Name = "first"
 stat.Value = d[1] or 0
 ds:SetAsync(player.UserId, stat.Value)
 stat.Changed:connect(function()
  ds:SetAsync(player.UserId, {stat.Value; 'Hi lol';)
 end)
 print(d[2])
end)


game.Players.PlayerRemoving:connect(function(player)
 local tbl = {player.places.first.Value; 'Hi lol'}
 ds:SetAsync(player.UserId, player.places.first.Value)
end)

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