I am doing some testing involving scopes in data stores. I am trying to load the data using a scope, and it gave an error saying:
519: Scope name exceeds the 50 character limit
I was quite puzzled because my scope name is only 14 characters long.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local dataStoreOptions = Instance.new("DataStoreOptions")
dataStoreOptions.AllScopes = true
local cashDataStore = DataStoreService:GetDataStore("CashDataStore", "", dataStoreOptions)
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success, result = pcall(function()
print("getting")
print(string.len((tostring(player.UserId)))) -- prints 9 (NOT INCLUDING SCOPE NAME)
data = cashDataStore:GetAsync(tostring(player.UserId))
end)
local dataStoreKeysPage = cashDataStore:ListKeysAsync()
while true do
local currentPage = dataStoreKeysPage:GetCurrentPage()
for index, value in pairs(currentPage) do
print(index, value.KeyName)
print(string.len(value.KeyName)) -- prints 14
end
break
end
if success then
print("successs")
if data then
print("it has data")
cash.Value = data
else
print("no")
end
else
print(result) -- prints the error stated above
end
leaderstats.Parent = player
end)
Is this supposed to be a bug? I found a similar post that has the same issue.
A potential fix you could implement is using string.sub to extract the first 14 characters and then save that instead? It might not be the first 14 characters - try printing out the value and seeing which characters you need, etc.
string.sub is a cool thing that essentially allows you to trim out any set of characters of a string. For example
local coolstringhello = "hello"
print(string.sub(coolstringhello, 1, 3)) -- prints "hel"
the arguments of string.sub are string.sub(string to be subbed, first character's index, last character's index
Remember, Roblox Lua is a 1-indexed programming language, so the first character has an index of !, not 0 (like in Python)
if you did string.sub(savedstring, 1, 14), it’d return the first 14 characters of savedstring. I believe that in your case, something is messing around with savedstring and so by isolating the true 14 characters that you need, you could fix it. Obviously, it might not be the first 14 characters that are needed, but perhaps the last 14 characters? Or the middle 14 characters - print out savedstring to find out which ones you actually need.
Judging by the situation, you’d need to do it for both saving and loading probably.
Hope this helps you understand a bit more.
From what I can test and what I have read up on, it’s because you’re using the AllScopes property.
Each key is assigned a scope, even if you don’t specify it. If you don’t specify the scope and you don’t have AllScopes specified for the DataStore, it’ll go to the global scope.
However, when you use the AllScopes property on the options, it doesn’t know what scope you want it to do so you’ll have to specify that yourself when using GetAsync, SetAsync, etc. You can read more into it here.
The error is that you’re not specifying a scope, but Roblox doesn’t seem to have an error made for this situation so it goes for the 50 character limit error instead.
Correct usage with this in mind would go something like this
-- "cash" is the scope name. The forward slash separates the scope from the key.
data = cashDataStore:GetAsync("cash/" .. tostring(player.UserId))
Hey, the way I solved the issue is by disabling AllScopes and just giving all Keys one Scope for example “Stats”.
For some reason it does not work with AllScopes. Not quite sure why.