I have a script which saves the donated value however there is an error which says Could not fetch Package Permissions Data: HTTP 504 (Gateway Timeout) .
My data is using data = http:JSONDecode(data)
Im thinking this maybe a problem. I really need a solution fast. Thanks.
game.Players.PlayerAdded:Connect(function(plr)
local donated = Instance.new("IntValue",plr:WaitForChild("leaderstats"))
donated.Name = "Donated"
local recieved = Instance.new("IntValue",plr:WaitForChild("leaderstats"))
recieved.Name = "Recieved"
local data
local success, errormsg = pcall(function()
data = donationStore:GetAsync(plr.UserId)
end)
if success then
if data then
data = http:JSONDecode(data)
plr.leaderstats.Donated.Value = data[1]
plr.leaderstats.Recieved.Value = data[2]
else
print("No previous data.")
end
else
print(errormsg)
warn(errormsg)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = {plr.leaderstats.Donated.Value,plr.leaderstats.Recieved.Value}
local success, errormsg = pcall(function()
data = http:JSONEncode(data)
donationStore:SetAsync(plr.UserId, data)
end)
if success then
print("Successfully saved.")
else
warn(errormsg)
end
for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
if stand.ClaimedUserName.Value == plr.Name then
module.clearStand(stand)
end
end
end)
You don’t need to use the JSONEncode to be able to store data inside the database as that is used when you want to decrypt an API.
Save it as a database and get it without the need to decrypt it just use “table[value]”.
I share with you your script already solved for this:
local DataStoreService = game:GetService("DataStoreService")
local donationStore = DataStoreService:GetDataStore("DonationData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local donated = Instance.new("IntValue", leaderstats)
donated.Name = "Donated"
local recieved = Instance.new("IntValue", leaderstats)
recieved.Name = "Recieved"
local data
local success, errormsg = pcall(function()
data = donationStore:GetAsync(tostring(plr.UserId))
end)
if success then
if data then
plr.leaderstats.Donated.Value = data[1]
plr.leaderstats.Recieved.Value = data[2]
else
print("No previous data for", plr.Name)
end
else
print("Error retrieving data for", plr.Name, ":", errormsg)
warn(errormsg)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = {plr.leaderstats.Donated.Value, plr.leaderstats.Recieved.Value}
local success, errormsg = pcall(function()
donationStore:SetAsync(tostring(plr.UserId), data)
end)
if success then
print("Successfully saved data for", plr.Name)
else
print("Error saving data for", plr.Name, ":", errormsg)
warn(errormsg)
end
for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
if stand.ClaimedUserName.Value == plr.Name then
module.clearStand(stand)
end
end
end)