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.
01 | local function onCompleteAppFired(player) |
02 | print ( "submit pressed" ) |
03 | local name = player.Name |
04 |
05 | local keep = game:GetService( 'DataStoreService' ):GetDataStore( 'keep' ):GetAsync( 'table' ) print (keep) --load 'keep' |
06 |
07 | local Q 1 A = workspace.info.answers.Q 1 A |
08 | local Q 2 A = workspace.info.answers.Q 2 A |
09 | local Q 3 A = workspace.info.answers.Q 3 A |
10 | local Q 4 A = workspace.info.answers.Q 4 A |
11 | local Q 5 A = workspace.info.answers.Q 5 A |
12 |
13 | (name) = { --make a table named as the players username |
14 | "Q1A" = (Q 1 A.Value), |
15 | "Q2A" = (Q 2 A.Value), |
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)
01 | local function onCompleteAppFired(player) |
02 | print ( "submit pressed" ) |
03 | local name = player.Name |
04 |
05 | local keep = game:GetService( 'DataStoreService' ):GetDataStore( 'keep' ):GetAsync( 'table' ) print (keep) --load 'keep' |
06 |
07 | local Q 1 A = workspace.info.answers.Q 1 A |
08 | local Q 2 A = workspace.info.answers.Q 2 A |
09 | local Q 3 A = workspace.info.answers.Q 3 A |
10 | local Q 4 A = workspace.info.answers.Q 4 A |
11 | local Q 5 A = workspace.info.answers.Q 5 A |
12 |
13 | keep [ player.UserId ] = { --use UserId to comply with data protection |
14 | [ "Q1A" ] = Q 1 A.Value, |
15 | [ "Q2A" ] = Q 2 A.Value, |
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"