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

How can I make this save data a table?

Asked by
Drakyd 1
4 years ago

Hey guys! I would like my Level save data to be put into a table as I'll have like 20-25 levels. Now the there is 3 save data. 1 and 2 should be ignored now. save data 3 is the one responsible for saving LevelOne's data. and I would like to make save data 3 a table to be able to save many level's boolvalue. Could you please help? I looked it up and I don't understand how can I make a table out of save datas. Thank you so much!

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CompleteSaveSystem")
local ds2 = datastore:GetDataStore("TTSaveSystem")
local ds3 = datastore:GetDataStore("LevelTrack")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local Complete = Instance.new("IntValue", folder)
 Complete.Name = "Completes"
 local TT = Instance.new("IntValue", folder)
 TT.Name = "Tree Tokens"
 local folder2 = Instance.new("Folder", plr)
 folder2.Name = "LevelTracking"
 local LevelOne = Instance.new("BoolValue", folder2)
 LevelOne.Name = "LevelOne"

 Complete.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, Complete.Value)

 TT.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, TT.Value)

 LevelOne.Value = ds3:GetAsync(plr.UserId)
 ds3:SetAsync(plr.UserId, LevelOne.Value)

 Complete.Changed:connect(function()
  ds1:SetAsync(plr.UserId, Complete.Value)
 end)

 TT.Changed:connect(function()
  ds2:SetAsync(plr.UserId, TT.Value)
 end)

 LevelOne.Changed:connect(function()
  ds3:SetAsync(plr.UserId, LevelOne.Value)
 end)

end)
0
I don't quite understand your question, are you asking how to save data in a datastore as a table? metalive 0 — 4y
0
Yes Drakyd 1 — 4y
0
First of all you should only store data when you're leaving the game as if you're storing it whenever it changes, and if it changes a lot it will error because there are too many storing updates. metalive 0 — 4y
0
It changes a very few times, but could you help me with what Ive asked please? Drakyd 1 — 4y
View all comments (8 more)
0
So you'd like to save 1 boolean in the table? metalive 0 — 4y
0
Right now yes, later 20-25 Drakyd 1 — 4y
0
You need to elaborate on your question I don't understand what you mean by "many level's boolvalue" metalive 0 — 4y
0
LevelOne is a bool value. I would like to have LevelTwo LevelThree and so on. Drakyd 1 — 4y
0
Why would you do that? metalive 0 — 4y
0
Its a system thar saves if you comeplted a level. Dont mind that Drakyd 1 — 4y
0
Well you could just store your completed levels in a table instead of having an individual value for all of them metalive 0 — 4y
0
For example: levelsCompleted = {} function levelCompleted(level) table.insert(levelsCompleted, #levelCompleted + 1, level) end levelCompleted(1) metalive 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

If you're simply just asking how to save data as a table that is it.

local data = {LevelOne = LevelOne.Value}
ds3:SetAsync(plr.UserId, data)
0
and If I'll have a LevelTwo? Drakyd 1 — 4y
0
The way you're going about saving what levels you've done is impractical and you're not using the best method to. You should add a level number you've completed to a table of all your completed levels then save that data metalive 0 — 4y
0
no, you can complete level 1 and level 3 and then you'll have two levels completed. it's complicated Drakyd 1 — 4y
0
Yes I know so you'll add 1 to a table to show you've completed level one and then you'll add 3 to the table to show you've completed level 3. metalive 0 — 4y
0
yes, but I don't really understand the given answer, sorry. But thank you Drakyd 1 — 4y
Ad

Answer this question