I have two script which saves data and I've been told that I can not save multiple datas. How do I put them together then?
script one
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("CompleteSaveSystem") local ds2 = datastore:GetDataStore("TTSaveSystem") 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" 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) Complete.Changed:connect(function() ds1:SetAsync(plr.UserId, Complete.Value) end) TT.Changed:connect(function() ds2:SetAsync(plr.UserId, TT.Value) end) end)
second:
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") -- Getting data store service Players.PlayerAdded:connect(function(player) local TrackersData = DataStoreService:GetDataStore(player.UserId.."Trackers") -- Getting data store local LevelTracker = Instance.new("Folder") LevelTracker.Parent = player LevelTracker.Name = "LevelTracker" local Level1 = Instance.new("BoolValue") Level1.Parent = LevelTracker Level1.Name = "Level1" Level1.Value = false local Value = TrackersData:GetAsync("Level1") -- Getting value from data store "TrackersData" if Value == nil then TrackersData:SetAsync("Level1",false) -- if value equals nothing then it'll creates it. else Level1.Value = Value end end)
I don't really understand what you exactly want, but I will explain something to you.
For databases, you can actually save more than 1 data value there.
I will show you on your first script.
local datastore = game:GetService("DataStoreService") local ds = datastore:GetDataStore("CompleteAndTT") --Only 1 datastore 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 data = ds:GetAsync(plr.UserId) --Gets data if data then --Checks if there is data for that player Complete.Value = data[1] --Get's first data from the ds TT.Value = data[2] --Second data else --No data Complete.Value = 0 TT.Value = 0 end ds:SetAsync(plr.UserId, {Complete.Value,TT.Value}) --Saves 2 datas --Now let's do some high-level scripting for i, child in pairs(folder:GetChildren()) do --Gets all the values child.Changed:connect(function() --If any of them changed ds:SetAsync(plr.UserId, {Complete.Value,TT.Value}) --Saves 2 datas end) end end)
Let me know if you have more questions