DataStoreService Help

I’ve been trying to use DataStoreService to store applications, using tables. I can save them, and retrieve them and what is inside them, but I don’t know how to create an application then save it or remove an application.

local Applications = {
	["1"] = {
		['Username'] = "h",
		['Questions'] = {},
		['Status'] = "Pending"
	};
	["2"] = {
		['Username'] = "asdads",
		['Questions'] = {},
		['Status'] = "Passed"
	};		
}
local DSS = game:GetService("DataStoreService"):GetDataStore("ApplyNow")
game.Players.PlayerAdded:connect(function(plr)
print(plr.Name.."joined")
local uniquekey = 'id-'..plr.userId
	
local GetSaved = DSS:GetAsync(uniquekey)

end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {Applications}
DSS:SetAsync(uniquekey, Savetable)
end)

I have built in two applications for testing, but I don’t know how to create an application and then save it into my DataStore.

2 Likes

I suggest indenting your code to make it more reasonable. Studio does this automatically for you in most cases.





GetChildren returns a table. You don’t need to put it into a table, that’s just going to cause an error (in theory at least).

Also, you can’t save instances (or tables with instances). You’re better off saving the values of what’s in script.Parent.Folder to the datastore.

What’s suppose to be in script.Parent.Folder anyway?


A few other issues that appeared to me:

  • What happens if there’s multiple players in the game?

I’m having difficulty understanding how your code is suppose to work. From my understanding…

  • Player joins
    • Store their saved data into a local variable (and do nothing with it)
  • Player leaves
    • Get a table of instances in script.Parent.Folder and save it to the player’s user ID

@ElliottLMz
Sorry, about that let me get the other code, as I mixed the code up slightly, the code is:

local player
local Applications = {
	["1"] = {
		['Username'] = "h",
		['Questions'] = {},
		['Status'] = "Pending"
	};
	["2"] = {
		['Username'] = "asdads",
		['Questions'] = {},
		['Status'] = "Passed"
	};		
}
local DSS = game:GetService("DataStoreService"):GetDataStore("ApplyNow")
game.Players.PlayerAdded:connect(function(plr)
player = plr
local uniquekey = 'id-'..plr.userId
	
local GetSaved = DSS:GetAsync(uniquekey)

end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {Applications}
DSS:SetAsync(uniquekey, Savetable)
end)

You can update specific things the same you’d set them.
Example:

local DSS = game:GetService("DataStoreService"):GetDataStore("ApplyNow")
local uniquekey = "id-"..plr.UserId
DSS:SetAsync(uniquekey, {Username=plr.Username, Questions={}, Status=''})

I believe this would work, if not tell me.

2 Likes

Thanks so much I’ll try that out.

table.remove can remove list items.

table.remove(Applications, "1") -- "1" or whatever ID you want to remove.

That should remove items, you just need to save it.

2 Likes

If this answered your issue can you mark it as solution? Or whichever one you seem best?