Whenever I use any type of datastore, I get this error:

  10:46:41.145 - 508: Exhausted all retries for key: %s 

I don't know whats wrong? Anyone know? Here is my script:

local Data = game:GetService("DataStoreService"):GetDataStore("Data0")

local prefix = "user_" -- example prefix


game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder", player)
    folder.Name = "leaderstats"

    local Kills = Instance.new("IntValue",folder)
 Kills.Name = "Kills"

    local Credits = Instance.new("IntValue",folder)
    Credits.Name = "Credits"

    local plrData = Data:GetAsync(prefix  .. tostring(player.UserId))

    if plrData then
          Kills.Value = plrData[1] or 0
          Credits.Value = plrData[2] or 0
   else
        -- most people like to save the data if they have none 

    Data:SetAsync(prefix  .. tostring(player.UserId), {
       Kills.Value,
        Credits.Value        
     })
   end

end)

game.Players.PlayerRemoving:connect(function(player)
    Data:SetAsync(prefix  .. tostring(player.UserId), {
        player.leaderstats.Kills.Value,
        player.leaderstats.Credits.Value 
    })
end)

10 comments

0

Is the problem on line 508 trying to save data? If so roblox studios doesent really do that. So what I usally do is locate the line that saves it to the bottom.

0

Its the bottom line. When the player is removing.

0

Are the leaderstats showing up though?

0

Yeah

0

It should be fine then, It will save ingame but not in studios.

0

Ok. Thank you. Let me see if it works.

0

Don't exactly understand the question but you should set the parent of the instance.new objects on another line instead of the second argument and you should use Connect instead

0

of connect

0

Use Connect instead of connect and not entirely sure why you're doing tostring(player.UserId), I normally just do "Stats-"..player.UserId