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

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

Asked by
danglt 185
5 years ago
Edited 5 years ago

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)
0
use an array to store all the values User#23365 30 — 5y
0
do a for i,v in pairs on the values parent Scarperino 20 — 5y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
Ad

Answer this question