What you could do
Make a dictionary. Dictionaries are tables with custom keys. You could make the keys the answer choices and the values the amount of times they're selected.
Dictionaries
When you make a dictionary you'd make you custom key by surrounding what would be your key with square brackets []
. Your key itself can be any lua value. Such as a float, boolean or even an object. As long as it isn't nil. And since a string isn't nil we can use it!
Now we need to set the key's value. We'll set it to 0 in this example.
Now whenever we check the value for Key
, we'll get 0.
0
Final Product
01 | local exampledatastore = Datastore:GetDataStore(example) |
13 | for table,v in pairs (exampledatastore) do |
15 | for key,value in pairs (exampledatastore [ v ] ) do |
16 | ExampleTable 1 [ key ] = value |
18 | elseif table = = 2 then |
19 | for key,value in pairs (exampledatastore [ v ] ) do |
20 | ExampleTable 2 [ key ] = value |
23 | for key,value in pairs (exampledatastore [ v ] ) do |
24 | ExampleTable 3 [ key ] = value |
34 | for i,v in pairs (ExampleTable 1 ) do |
35 | number = math.max(number,v) |
36 | table.insert(popularanswer,i) |
40 | for _,v in pairs (ExampleTable 2 ) do |
41 | number = math.max(number,v) |
42 | table.insert(popularanswer,i) |
46 | for _,v in pairs (ExampleTable 3 ) do |
47 | number = math.max(number,v) |
48 | table.insert(popularanswer,i) |
51 | print ( "The most popular answers were as follows: " ..table.concat(popularanswer, ", " ).. "." ) |
Hope it helps!