Datastore error

  1. I’m using SetAsync to save something to datastore

  2. The error 519: Scope name exceeds the 50 character limit.
    The key for this is randomly generated by math.random(0, 10000).
    The datastore has AllScopes enabled and the scope is just “” (a bypass to get all keys basically.)

  3. I thought that maybe theres decimals in the math.random so i used math.floor, i was wrong

a part of the code (the only part needed as far as I know)

local options = Instance.new("DataStoreOptions")
options.AllScopes = true
local DSS = game:GetService("DataStoreService")

local NationDS = DSS:GetDataStore("Nations", "", options)

		local success, errorMessage = pcall(function()
			NationDS:SetAsync(nationKey, t)
		end)

(the error printed is the variable errorMessage)
(The variable t is a JSON)

How does the name get generated?

The key name gets generated as mentioned in the post by using:

math.floor(math.random(0, 10000))

(the math.floor() is there because I was not sure if it generated decimals and that those are the problem)

Try do:

tostring(math.floor(math.random(0, 10000)))

I have tried this not long after I created the post aswell but it didn’t change anything.
Also Im not quite sure if scope name refers to key name I’m just guessing

The error message is indicating that the scope name is exceeding the 50 character limit.

One possible solution is to shorten the scope name. You can try using a hash function to generate a shorter string from the nation key. For example, you could use the string.sub function to extract the first few characters of the hash result.

Another solution is to use a custom key for the datastore, instead of relying on the math.random function to generate a random key. For example, you could use the name of the nation as the key, or a combination of the name and some other unique identifier.

If you need to keep the randomly generated key, you could store the key-value pair in a different datastore with a shorter scope name.

The thing is that the generated key was just 8241 or so, it was just 4 numbers.

Just so you know, math.floor() is useless here as math.random() only returns Integers, not Floats (aka Doubles for some reason)

For that Functionality, use Random.new():NextNumber() which will return a random Float.

I don’t think this works this way, maybe try replacing "" with "global" or better yet with nil?

nil does not work since I am using options, “global” does not work either since AllScopes requires to have the scope be an empty string.

1 Like

1 Like

The name of my Datastore is “NationDS”, 8 characters
The Key is just a few numbers
Not quite sure what exactly the scope is but the datastore one is just “”
The Data getting saved is around 41 characters

I just changed the way I do this and disable allScopes and use something else.
There seems to be no fix to this I believe it is a Roblox Bug