In short
Every DataStore key can be at most 50 characters long. Longer keys fail with error 102 and nothing is saved or loaded. Build keys from a short prefix and the player's UserId, such as "Player_" .. player.UserId, which is always well under the limit and never changes when the player renames.
What the message means
ServerScriptService.PlayerData:21: 102: Key name exceeds the 50 character limit.
Error codes in the 100s come from the data store itself, before any request is sent. 102 always means the key is too long.
Data store names have their own limit, also 50 characters. The value you save can be much larger; the 50 character rule is only for names and keys.
Causes and fixes
Two things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
A long prefix or a name in the key
Descriptive keys like "PlayerInventoryAndSettingsSaveData_" plus a display name grow past 50 characters for some players only, so the bug shows up randomly.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local store = DataStoreService:GetDataStore("PlayerData")
Players.PlayerAdded:Connect(function(player)
local key = "PlayerInventoryAndSettingsSaveData_" .. player.DisplayName .. "_" .. player.UserId
local data = store:GetAsync(key)
print(data)
end)
Use a short prefix and the UserId only, and keep the call in a pcall.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local store = DataStoreService:GetDataStore("PlayerData")
Players.PlayerAdded:Connect(function(player: Player)
local key = "Player_" .. player.UserId
local ok, data = pcall(function()
return store:GetAsync(key)
end)
if ok then
print(key, data)
else
warn("Load failed for", key, data)
end
end)
Data was put into the key
Building a key from a list of items or encoded JSON makes it as long as the data. Data belongs in the value, not the key.
local DataStoreService = game:GetService("DataStoreService")
local HttpService = game:GetService("HttpService")
local store = DataStoreService:GetDataStore("Builds")
local function saveBuild(userId: number, parts: { string })
local key = userId .. HttpService:JSONEncode(parts)
store:SetAsync(key, true)
end
Keep the key short and store the data as the value. Data stores save tables directly.
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("Builds")
local function saveBuild(userId: number, parts: { string })
local key = "Build_" .. userId
local ok, err = pcall(function()
store:SetAsync(key, parts)
end)
if not ok then
warn("Save failed for", key, err)
end
end
saveBuild(1, { "Wall", "Door" })
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
What is the best DataStore key for a player?
A short prefix and the UserId, like "Player_123456". The UserId never changes, even when the player changes their name.
Does the limit count bytes or characters?
The message says characters. Keep keys to plain letters, digits and underscores and the difference never matters.
How big can the saved value be?
Much bigger than the key: the Roblox data store limits page lists the current value size limit. Tables are saved as JSON for you.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It shortens the keys in your place and, if needed, moves data out of the key into the value.
Sources and further reading
- Roblox Creator Docs: data store error codes and limits. error 102 and the key and name length limits
- Roblox Creator Docs: data stores
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.