Hi I was making a game where to player collects coins and it would save to DataStore. Whenever I play it says 502: API Services rejected request with error. HTTP 403 (Forbidden) On other posts I’ve seen people say that it was because they weren’t the owner of the place, however I am the owner.
Source Of This Problem
local DSS = game:GetService(“DataStoreService”)
local Money = DSS:GetDataStore(“Coins”)
game.Players.PlayerAdded:Connect(function(plr)
local pCoins = Money:GetAsync(plr.UserId)or 0
local leaderstats = Instance.new(“Folder”,plr)
leaderstats.Name = “leaderstats”
local CoinValue = Instance.new(“NumberValue”)
CoinValue.Name = “Coins”
CoinValue.Value = pCoins
-- Set up table to return to any script that requires this module script
local PlayerStatManager = {}
local DataStoreService = game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)
– Table to hold player information for the current session
local sessionData = {}
Oh it was working a few days ago? Datastore probably broke, but I would replace the code just to be sure. (I don’t know much on datastore breaks because I’ve never had that issue before so I can’t say for sure if it broke.)
I added it in like this, but it still didn’t work. It said 502: API etc. and when I clicked on it, it brought me to line six. I also lost my progress of this past weeks work. Then I redid everything. Could that have been the reason why this isn’t working, and could a virus from free models cause my work to be deleted?
local DSS = game:GetService(“DataStoreService”)
local Money = DSS:GetDataStore(“Coins”)
game.Players.PlayerAdded:Connect(function(plr) local pCoins
if Money:GetAsync(plr.UserId) ~=nil and Money:GetAsync(plr.UserId) ~= “” then
pCoins = Money:GetAsync(plr.UserId)
else
pCoins = 0
end
local leaderstats = Instance.new(“Folder”,plr)
leaderstats.Name = “leaderstats”
local CoinValue = Instance.new(“NumberValue”)
CoinValue.Name = “Coins”
CoinValue.Value = pCoins
-- Set up table to return to any script that requires this module script
local PlayerStatManager = {}
local DataStoreService = game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)
– Table to hold player information for the current session
local sessionData = {}
Hmm line 6 is the GetAsync() line. Something must be wrong there.
Okay, I have copied and pasted the script exactly without;
-- Set up table to return to any script that requires this module script
local PlayerStatManager = {}
local DataStoreService = game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)
-- Table to hold player information for the current session
local sessionData = {}
local AUTOSAVE_INTERVAL = 10
and it worked completely fine. I believe it is your place that may be the problem. Again check to see if studio has API Services enabled or try the script in a different place to confirm that the place that this script is in currently is the problem.
Exact script I used;
local DSS = game:GetService("DataStoreService")
local Money = DSS:GetDataStore("Coins")
game.Players.PlayerAdded:Connect(function(plr)
local pCoins
if Money:GetAsync(plr.UserId) ~=nil and Money:GetAsync(plr.UserId) ~= "" then
pCoins = Money:GetAsync(plr.UserId)
else
pCoins = 0
end
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local CoinValue = Instance.new("NumberValue")
CoinValue.Name = "Coins"
CoinValue.Value = pCoins
CoinValue.Parent = leaderstats
CoinValue.Changed:connect(function(v)
Money:SetAsync(plr.UserId,v)
print("Money Saved")
end)
end)
Okay I fixed your issue, the main problem is because you were testing solo mode in studio though.
local Players = game:GetService("Players")
local datastoreservice = game:GetService("DataStoreService"):GetDataStore("TEST")
Players.PlayerAdded:Connect(function(player)
local key = player.userId
local playerData = datastoreservice:GetAsync(key)
if playerData then
print(playerData.a, playerData.b)
else
print'no data'
end
end)
Players.PlayerRemoving:Connect(function(player)
local data = {
}
data.a = 1
data.b = 2
local key = player.userId
datastoreservice:SetAsync(key, data)
end)
Ok, this code doesn’t shows the error, but at same time it doesn’t save anything when the user exits… Always shows ‘no data’, SetAsync not saving… (crazy Roblox Server behaviors)…
In time: today I tested my original code again and TODAY IT’S NOT SHOWING THE ERROR. And not saving anything though…