I have API services turned on as well as http requests. I have even tried testing it outside Roblox Studio and inside the game on the website. Still, my data is not being saved. I have asked for help from multiple people and they don't know what the reason is. Thanks for any help.
The code I wrote is as follows...
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
-- Load Data
game.Players.PlayerAdded:Connect(function(plr)
wait(3)
local plrKey = "id_"..plr.userId
local CashSave = plr.leaderstats.Cash
local GetSaved = ds:GetAsync(plrKey)
if GetSaved then
CashSave.Value = GetSaved[1]
else
local NumberForSaving = {CashSave.Value}
local success, errormessage = pcall(function()
ds:GetAsync(plrKey, NumberForSaving)
end)
if success then
warn("Data successfully loaded")
else
warn("Error when attempting to load data.")
end
end
end)
-- Save Data
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
ds:SetAsync("id_"..plr.userid, {plr.leaderstats.Cash.Value})
end)
if success then
warn("Data successfully saved.")
else
warn("Error when attempting to save data.")
end
end)
