[Datastore Issue] Internal Server Error Occured API: Get Async Data Store

I been using this code to save values in my game, it worked perfectly well for months but it was until this few days when I was working in the studio this bug happened to me twice while I busy testing.


image

This is odd as it never happened until these few days, perhaps is this not related to the code/script itself and it’s the fault of the internal server whatever?

local dataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local saveFileStore = dataStoreService:GetDataStore("SaveFileStore")
local Players = game:GetService("Players")

--[[-----------------------------------------------------
------------------------Functions------------------------
--]]-----------------------------------------------------

--Setup values for newbies
local function CreateValues(file)
	for _, value in pairs(script.Values:GetChildren()) do
		if not file:FindFirstChild(value.Name) then
			local valueClone = value:Clone()
			valueClone.Parent = file
		end
	end
end

local function TablizeObjects(array,file)
	for i, object in pairs(file:GetChildren()) do
		local objectName = object.Name

		if object:IsA("ValueBase") then
			array[objectName] = {
				["ValueType"] = object.ClassName,
				["ValueName"] = objectName,
				["ValueValue"] = object.Value
			}
		end
	end
end

--[[-----------------------------------------------------
----------------------Save the file----------------------
--]]-----------------------------------------------------

Players.PlayerRemoving:Connect(function(player)
	local file = player:WaitForChild("SaveFile")
	local playerUserID = player.UserId
	local saveFileArray = {}

	TablizeObjects(saveFileArray,file) --Create array

	local setSuccess, errorMessage = pcall(function()
		saveFileStore:SetAsync(playerUserID, saveFileArray) --Save array
	end)
	if not setSuccess then
		warn(errorMessage)
	end
end)

--[[-----------------------------------------------------
----------------------Load the file----------------------
--]]-----------------------------------------------------

Players.PlayerAdded:Connect(function(player)
	local playerUserID = player.UserId

	local getSuccess, loadSaveFile = pcall(function()
		return saveFileStore:GetAsync(playerUserID) --Pull store data
	end)
	
	local file = Instance.new("Folder", player) --Create SaveFile folder
	file.Name = "SaveFile"

	if getSuccess and loadSaveFile then
		--Start adding in the folder contents
		for i, object in pairs(loadSaveFile) do
			local valueType = object["ValueType"]
			local valueInstance = Instance.new(valueType)
			valueInstance.Parent = file
			valueInstance.Value = object["ValueValue"]
			valueInstance.Name = object["ValueName"]
		end

	end

	CreateValues(file)

end)
2 Likes

delete the script when you were testing and the items that go to the script and see what happens.

Datastores can’t be used in studio unless you have API access in studio on in the game’s settings. If you have that off, datastores won’t work while you test in studio. It’s probably better to leave it off or else make a private copy of your game with API access on unless you really need to, as things you do while testing in studio will affect the live data store.

1 Like

So basically, your saying that this script itself has no error?

If you have not turned on API access in studio on (it’s off by default) then it’s very likely not the script, it’s an intended result of having API access off to protect your live data store, then Yes. It’s the same error message I see when API access is off in my game.

If you would like to turn it on for some reason (going by the advice in my last reply) you can find the setting to turn API access in studio on at the bottom of “content settings”.

But my APi access is on… hmm idk

Then… yea, I apologize. I was going off the error message and I’m not sure if I understand datastores enough to say beyond that. :frowning:

1 Like

Also got an error about this. It seems like Roblox has sometimes problem with their server which indicate why it prints this incongruous message (DataStoreService: InternalServerError: An internal server error occurred. API: GetAsync, Data Store: MyDataStore)

1 Like