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

datastore error while trying to save?

I am trying to get it to save seconds, and later on Hours and minutes. but it keeps saying API Services rejected request with error. HTTP 403 (Forbidden)

datastoreservice = game:GetService("DataStoreService")
datastore = datastoreservice:GetDataStore("TimeSaving")

game.Players.PlayerAdded:Connect(function(player)
	local timer = script.Time:Clone()
	timer.Parent = player
	
	local data
	local success,errormessage = pcall(function()
		local data = datastore:GetAsync(player.UserId.."-TimePlayed")
	end)
	if success then
		timer.Seconds.Value = data
	else
		print("Error loading data")
		warn(errormessage)
	end
	
	while true do
		wait(1)
		timer.Seconds.Value = timer.Seconds.Value + 1
		if timer.Seconds.Value == 60 then
			timer.Seconds.Value = 0
			timer.Minutes.Value = timer.Minutes.Value + 1
		end
		if timer.Minutes.Value == 60 then
			timer.Minutes.Value = 0
			timer.Hours.Value = timer.Hours.Value + 1
		end
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	local success,errormessage = pcall(function()
		local seconds = player.Time.Seconds.Value
		local minutes = player.Time.Minutes.Value
		local hours = player.Time.Hours.Value
		datastore:SetAsync(player.UserId.."-TimePlayed",seconds)
	end)
		
	if success then
		print("Player data saves")
	else
		print("Issue saving data")
		warn(errormessage)
	end
end)

1 answer

✓ Accepted answer

To run DataStores, you need to enable API access to your Game. This can only be done through published places, and can be easily turned on by opening the Home banner in studio and heading to Game > Options, and turning on API Services.


This issue may also occur if you’re not the valid owner of said place.

2 comments

0

API services is on, but the game is owned by a group.

0

Only the owner of the TC can make DataStore requests then.

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