So, I'm trying to make a DataStore for cash in a game. For some reason, even after enabling API Services in the Studio settings, I still get the error message:
"502: API Services rejected request with error. HTTP 403 (Forbidden)"
(Proof of enabling API Services: https://prnt.sc/t1l1p7)
Here is my code:
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local cashDataStore = DataStoreService:GetDataStore("cashDataStore")
game.Players.PlayerAdded:Connect(function(player)
cashCounter = player.PlayerGui:WaitForChild("StarterScreenUI").sideGui.Frame.cash
local cashData
local success, errormessage = pcall(function()
cashData = cashDataStore:GetAsync(player.UserId.."-cash")
end)
if success then
cashCounter.Text = "$"..cashData
else
cashDataStore:SetAsync(player.UserId.."-cash",200)
cashData = cashDataStore:GetAsync(player.UserId.."-cash")
cashCounter.Text = "$"..cashData
end
return cashCounter
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
cashDataStore:SetAsync(player.UserId.."-cash",cashCounter.Text)
end)
if success then
print("Success")
else
warn(errormessage)
end
end)
ReplicatedStorage.Events.PurchaseSaveEvent.OnServerEvent:Connect(function()
end)
while wait(2) do
cashData = cashData + 1
cashCounter.Text = "$"..cashData
print(cashCounter.Text)
end

6 comments
Whats the point of saving to the datastore if a Error occured?
Enable API Service usingg the settings.
Heres the answer, no need to thank me, I'm just kind. https://scriptinghelpers.org/questions/104514/please-help-145039242-502-api-services-rejected-request-with-error-http-403-forbidden#96457
@Dovydas118, he said he already enabled API service.
@JesseSong It's in my own game. No TC enabled.
Are you sure? Because I don't know the answer to this other than Team create.