Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

“502: API Services rejected request with error. HTTP 403 (Forbidden)”?

I am trying to make data stores in my game and it keeps popping up with this message, “502: API Services rejected request with error. HTTP 403 (Forbidden)”.

The error occurs on line 25

local DSS = game:GetService("DataStoreService")

local datastore = DSS:GetDataStore("GeneralSaveData", "Players")

function generateDataKey(player)
	local ret = "uid_" .. player.userId
	return ret
end

function generateDataTable(player)
	local dataTable = {
		Coins = game.StarterPack.PlayerAssets.Value.Value,
	}
	return dataTable
end

function saveDataForPlayer(player)
	local key = generateDataKey(player)
	local data = generateDataTable(player)
	datastore:SetAsync(key, data)
end

function loadDataForPlayer(player)
	local key = generateDataKey(player)
	local data = datastore:GetAsync(key)
	inputDataToPlayer(player, data)
end

function inputDataToPlayer(player, data)
	game.StarterPack.PlayerAssets.Value.Value = data.Coins
end

game.Players.PlayerAdded:Connect(function(player)
	loadDataForPlayer(player) -- loads when join
	game.StarterPack.PlayerAssets.Value.Value.Changed:Connect(function()
		saveDataForPlayer(player) -- saves when wins changes
	end)
end)

game.Players.PlayerRemoving:Connect(saveDataForPlayer) -- saves when leave

1 answer

✓ Accepted answer

You need to turn on "Enable Studio Access to API Services" in your game settings, located under security.

3 comments

0

This seems to have worked but now it says "Workspace.Script:30: attempt to index nil with 'Coins' " on line 30

0

try using an if statement to see if the key is in the datastore. something like if data then, since it might not exist.

0

it might be because you defined "data" in a different function and not the current function on line 30 so it doesn't know about this other variable

This discussion is preserved as it was. New answers, comments, and votes are closed.