Okay- I am very much new to scripting, so there is a chance that the issue is very obvious. The code below -works-, as in, almost all of it but one single line.
local serverScriptService = game:GetService("ServerScriptService")
local dataStoreService = game:GetService("DataStoreService")
local httpService = game:GetService("HttpService")
local dataValues = script.dataValues
local serverModules = serverScriptService.serverModules
local dataStore = dataStoreService:GetDataStore("player_Data2")
--Load Data
game.Players.PlayerAdded:Connect(function(plr)
local success, err = pcall(function()
local key = "ID-".. tostring(plr.UserId)
local getSave = dataStore:GetAsync(key)
local dataFolder = Instance.new("Folder", plr)
dataFolder.Name = "dataFolder"
--Creates a copy of all datavalues and pastes them into DataFolder. It also makes sure each player has updated datavalues if I add a new one.
for i, v in pairs(dataValues:GetChildren()) do
local newData = Instance.new(v.ClassName)
newData.Name = v.Name
newData.Value = v.Value
newData.Parent = dataFolder
end
--Check if the player already has data
if getSave then
--Has data, so we simply load the saved values into the values in the dataFolder
for i, v in pairs(dataValues:GetChildren()) do
local decodedData = getSave
dataFolder[v.Name].Value = decodedData[i]
print(i, v.Name, v.Value)
end
else
--Does not have data, so we create an array of data for them.
local saveData = {}
for i, v in pairs(dataFolder:GetChildren()) do
table.insert(saveData, v.Value)
print(i, v.Name, v.Value)
end
local encodedData = httpService:JSONEncode(saveData)
dataStore:SetAsync(key, encodedData)
end
end)
if err then
print("Error Loading Data.")
end
end)
--Save Data
game.Players.PlayerRemoving:Connect(function(plr)
local success, err = pcall(function()
local dataFolder = plr:WaitForChild("dataFolder")
local dataList = dataFolder:GetChildren()
local key = "ID-".. tostring(plr.UserId)
local saveData = {}
for i, v in pairs(dataList) do
table.insert(saveData, v.Value)
print(i, v.Name, v.Value)
end
local encodedData = httpService:JSONEncode(saveData)
dataStore:SetAsync(key, encodedData)
end)
if err then
print("Error Saving Data.")
end
end)
The issue comes in game.Players.PlayerRemoving... Specifically this line, " dataStore:SetAsync(key, encodedData)". Everything up to that point works, just for some reason it doesn't save the data, albeit, when the player joins, and has no data, the same code does work. So I am confused about this.

4 comments
Quick question, you say "the issue comes in ... specifically this line ..." but what exactly is the error code you are receiving?
FYI you don’t need to encode your data into JSON before saving because Roblox does that automatically for you.
SerpentineKing, I wasn't receiving any error code, just the pcall was erroring out. But I fixed it below, figured out how to do so last night. But, I am not 100% sure the fix is the best thing.
Thanks for the info Rheines! Guess I must've got faulty information 'cus I saw people claiming you need to do so with an array. I'll change that up then.