It doesn’t though, I wonder if I should reference “dataToSave” too.
It doesn’t though, I wonder if I should reference “dataToSave” too.
Could you send your current save script?
–local DataStore = game:GetService(“DataStoreService”)
local gameData = DataStore:GetDataStore(“data 2”)
local Storage = script.Storage:GetChildren()
local maxLevel = 5000
local function saveData(plr, folder)
warn(“Saving Data…”)
local dataToSave = {}
for i, folders in pairs(folder:GetChildren()) do
--Making SubTables or Tables inside the main table
dataToSave[i] = {}
for j, data in pairs(folders:GetChildren()) do
dataToSave[i][j] = data.Value
print(data.Name, dataToSave[i][j])
end
end
gameData:SetAsync(plr.UserId.."-dataToSave", dataToSave)
warn("Data Saved!")
end
game.Players.PlayerAdded:Connect(function(newPlr)
local PlrStats = Instance.new(“Folder”,newPlr)
PlrStats.Name = “PlrStats”
--Generating new Data
for i, folders in pairs(Storage) do
local newFold = folders:Clone()
newFold.Parent = PlrStats
end
--Looking for saved Data
local saves = gameData:GetAsync(newPlr.UserId.."-dataToSave")
--If the player has saved data
if saves then
warn("Player Data Found!")
--Loading data
for i, folders in pairs(PlrStats:GetChildren()) do
for j, data in pairs(folders:GetChildren()) do
data.Value = saves[i][j]
print(i,j,data.Name,data.Value)
end
end
--If the player doesn't have saved data
else
warn("Player Doesn't have Data...")
end
while wait() do
local exp = PlrStats:WaitForChild("PlrInfo"):WaitForChild("Exp")
local level = PlrStats:WaitForChild("PlrInfo"):WaitForChild("Level")
local Points = PlrStats:WaitForChild("PlrInfo"):WaitForChild("Points")
local extraLevel = level.Value
local expNeed = ((extraLevel * 2)-1) * 15
if level.Value < maxLevel then
if exp.Value >= expNeed then
--Increase level by 1
level.Value = level.Value + 1
--Remove needed exp
exp.Value = exp.Value - expNeed
--Add points based on every level
Points.Value = Points.Value + 2
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(oldPlr)
local PlrStats = oldPlr:WaitForChild(“PlrStats”)
saveData(oldPlr,PlrStats)
end)–
Is this what you’re using to save the data?
Yes and then it fires this function.
I just want to know how to print my data from another script by using GetAsync.
Ah, got it. You should be able to print it as normal.
Try doing print(myData)
. It appears you have the new output so that should be able to print.
So it would print all the data by just doing this?
Yep, it should print the table.
It prints “nil” its like it wont get the data does it have to do with the datastores
I see. You have to get the same datastore on both scripts, being either “data 2” or “data 3”. It’s getting two separate datastores with two separate values.
Aight I see it now it doesn’t print nil this time but it printed a table with dots “{…}”. Is there any way behind this?
Yep. You have to click on those dots, or there might be an arrow beside it, and you’re able to browse the table.
Thank you so much for helping me! Finally understand!
I have one last simple question, I tried changing the value using SetAsync and it didn’t change, The GetAsync function works but to change the value and using SetAsync is giving me trouble. I’d appreciate if you’d explain that too and thanks!
Here’s the script.
Is your key the same amongst all of your scripts?
Do you mean the players UserId?
When you do :SetASync, the first argument is your key, in your case it would be plr.UserId.."Guild".."Member"
. Is this the key in all of your DS scripts?
I see. Well I don’t use strings with the players data is that the problem, I usually only have the player’s UserId with out a string with it, is the string important for changing the Values in other scripts?
Yeah, you’d have to :SetAsync with the entire table, you can’t index and update a specific value like that.
So in the datasave script I should put the strings, in GetAsync and SetAsync, and then I will be able to change it from another script by using that same string?