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

Why can i save with Datastores?

When ever I try to save using datastores I get this error:

502: API Services rejected request with error. HTTP 403 (Forbidden) Stack Begin Script 'ServerScriptService.PlayerStast', Line 20 Stack End

this is my code:


local DSS = game:GetService("DataStoreService")

--Data stores
local ds = DSS:GetDataStore("Cash") ---Cash


game.Players.PlayerAdded:Connect(function(player)
	--PlayerStats
	local stats = Instance.new("Folder")
	stats.Name = "PlayerStats"
	stats.Parent = player
	
	--Cash
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = stats
	cash.Value = ds:GetAsync(player.UserId.."-cash") or 100
	cash.Changed:Connect(function()
		ds:SetAsync(player.UserId.."-cash",player.PlayerStats.Cash.Value)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	ds:SetAsync(player.UserId.."-cash",player.PlayerStats.Cash.Value)
end)

3 comments

0

I awnsered your question

0

no you havent it is still not working.  Also it works fine on my brothers account

0

i have created a new game and it works

2 answers

✓ Accepted answer

Hello there, simple solution:

1. Go to the Develop page

2.Click on the Games tab and find your game

3.Click on the gear drop down and click "Configure"

4.Check the box labeled "Enable Studio Access to API Services:"

The reason for this is because ROBLOX Studio needs Acess to the API services inorder to read and send data from the client, thus requiring you to permit them to do so. Other than that the code will not work, especially in studio. Follow the steps in order to solve your problem.

2 comments

0

Unlike the other awnser I explained what to do and gave you a reasoning. Please tell me if you have any more questions regarding DataStores and API services

0

Ive logged on to the owners account (my brother (we are creating a game together)) and it worked fine. But when i logged back on to my account it didnt work again

you should enable api services in order to do that you must go to game settings in the home tab in roblox studio then go to options and enable api services please accept this answer :)))

1 comment

0

I have and it still has not worked

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