local RS = game:GetService(“ReplicatedStorage”):FindFirstChild(“SubmitCode”)
local DSS = game:GetService(“DataStoreService”)
local DataStore = DSS:GetDataStore(“DataDATADATA”)
game.Players.PlayerRemoving:Connect(function(player)
local stats = player:WaitForChild("ChatColor")
local playerKey = "ChatColor_"..player.UserId
local itemTable = {}
for index, item in pairs(stats:GetChildren())do
itemTable[item.Name] = item.Name -- saving the item name to item name to be able to load again!
end
local success, errormessage = pcall(function()
DataStore:SetAsync(playerKey, itemTable)
end)
if errormessage then
print("Fail To Save!")
else
if success then
print("saving successfully!")
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "ChatColor"
local playerKey = "ChatColor_"..player.UserId
local codesData
local success, errormessage = pcall(function()
codesData = DataStore:GetAsync(playerKey)
end)
if success then
else
print("Avatar failed to load!")
warn(errormessage)
end
if type(codesData) == "table" then
for index, value in pairs(codesData) do
local b = Instance.new("BoolValue") -- what you create, string, int or folder needs the same,
b.Name = value -- using value or any variables codesData is the value, you can either use v or value,
b.Parent = player.ChatColor -- parenting it to the folder you wish to save!
print(b.Name.."Saved successfully!")
end
end
end)
Provide an overview of:
-
What does the code do and what are you not satisfied with?
I already know how to save both Name’s and Value’s, but I don’t know how to save the VALUE data in a table… -
What potential improvements have you considered?
The code I have above can only save the names, I tried other methods, but I always got an error, I search up online, but none of them can save the data, I know there is, but it can only save the value if they already have parented the folder and the children to a folder, example a leaderstats, the stage, coins have already parented so its easily to save them using Coins.Value = Data.Coins, but it doesnt work on table, I know I am asking an obvious question but I am beginner just started last march 2 and this is the first time I have trouble understanding this, sorry for my English