[SOLVED] Saving & Loading strings in tables?
Asked by
4 years ago Edited 4 years ago
Yes, there are numerous threads on this on here, and yes I've looked at about all off them but none of them are in the same situation as mine.
In my situation, the strings are being made with specific names as the player is playing. I've just got a folder in workspace called Inventory with folders in it with the names of each player online. Whenever something gets added a string gets made & added to the players folder
with the correct name. All I need to save & load are the names of each of the strings, not the values.
I'm an absolute noob at datastores and I just don't fully get this. I've looked at a crap ton of wiki pages, scriptinghelpers posts, a reddit post and other things and adapted my code but I just don't fully get it just yet. None of them explain in good detail what I'm confused at.
Here's what I have,
01 | local Players = game:GetService( "Players" ) |
02 | local ServerStorage = game:GetService( "Workspace" ) |
03 | local DataStoreService = game:GetService( "DataStoreService" ) |
04 | local DataStore = DataStoreService:GetDataStore( "Inventory" ) |
06 | Players.PlayerAdded:Connect( function (player) |
08 | local folder = Instance.new( "Folder" ) |
09 | folder.Parent = ServerStorage.Inventory |
10 | folder.Name = (player.Name) |
11 | local PlayerData = DataStore:GetAsync(player.UserId) |
12 | for i, v in pairs (PlayerData) do |
13 | local value = Instance.new( "StringValue" ) |
20 | local function playerLeaving(player) |
23 | for i, v in pairs (ServerStorage.Inventory:FindFirstChild(player.Name):GetChildren()) do |
24 | table.insert(inv, v.Name) |
28 | DataStore:SetAsync(player.UserId, inv) |
31 | ServerStorage.Inventory:FindFirstChild(player.Name):Destroy() |
34 | game.Players.PlayerRemoving:Connect(playerLeaving) |
36 | game:BindToClose( function () |
37 | for _, player in pairs (game.Players:GetPlayers()) do |
When the player rejoins it supposedly should take all of the string values out of the table and create strings for each one renamed to the appropriate title and put in the players folder.
Not really getting any errors, it just doesn't work.
However, I am getting this in console
17:22:03.523 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = (an 8 digit string of numbers)
I'm mostly confused at loading all of the values when the player joined. Haven't seen anyone explain that really anywhere.
EDIT : I fixed 1 wrong line, tried in a live-game, still doesn't work. However, I added a print between lines 15 & 16 that looks like
1 | print (v.Name.. " Loaded" ) |
And it comes up as
attempt to concatenate nil with string