I am trying to make an application form game. Right now I am to the point where I have answers to questions stored in a folder (workspace.info.answers). I am going to take the answers, put them into a table which is named as their username. I'm just clueless on how to make the table named as their username, then put it into the 'keep' table.
local function onCompleteAppFired(player) print("submit pressed") local name = player.Name local keep = game:GetService('DataStoreService'):GetDataStore('keep'):GetAsync('table') print(keep) --load 'keep' local Q1A = workspace.info.answers.Q1A local Q2A = workspace.info.answers.Q2A local Q3A = workspace.info.answers.Q3A local Q4A = workspace.info.answers.Q4A local Q5A = workspace.info.answers.Q5A (name) = { --make a table named as the players username "Q1A" = (Q1A.Value), "Q2A" = (Q2A.Value), "Q3A" = (Q3A.Value), "Q4A" = (Q4A.Value), "Q5A" = (Q5A.Value) } keep.(name) = (name) --add the tabel to 'keep' DataStoreService:GetDataStore('keep'):SetAsync('table',keep) --save 'keep' end
This function is running, as I am getting "submit pressed" in the output.
since its being put into a table you can use table indexing to name your variable as a string.
keep[player.Name] = {what ever thetableis}
How about this (nested tables):
(You may need to purge old keep table from data strores)
local function onCompleteAppFired(player) print("submit pressed") local name = player.Name local keep = game:GetService('DataStoreService'):GetDataStore('keep'):GetAsync('table') print(keep) --load 'keep' local Q1A = workspace.info.answers.Q1A local Q2A = workspace.info.answers.Q2A local Q3A = workspace.info.answers.Q3A local Q4A = workspace.info.answers.Q4A local Q5A = workspace.info.answers.Q5A keep[player.UserId] = { --use UserId to comply with data protection ["Q1A"] = Q1A.Value, ["Q2A"] = Q2A.Value, ["Q3A"] = Q3A.Value, ["Q4A"] = Q4A.Value, ["Q5A"] = Q5A.Value } DataStoreService:GetDataStore('keep'):SetAsync('table',keep) --save 'keep' end
Edit: Sorry I forgot about brackets.
Edit 2: Ok I have tried to run it, and it actually does not work. I do apologize, while I have been using nested tables a lot, I actually never tried to save them to data strores, which seems is not supported. I get
" 23:59:36.363 - Cannot convert mixed or non-array tables: keys must be strings"