01 | local TableToMatchAccordingToIndex = { Cash = 0 , Money = 0 , ChaChing = 0 } |
02 | local PlayersData = { Cash = 123566 , Money = 2345 , ChaChing = 1231213 } |
03 |
04 |
05 | for i,v in pairs (TableToMatchAccordingToIndex) do |
06 |
07 | for k,d in pairs (PlayersData) do |
08 |
09 | if i = = k then |
10 |
11 | v = d |
12 |
13 | end |
14 |
15 | end |
The problem is because you're changing the v
variable when you want to overwrite the index. This is the equivalent.
1 | local Val = script.Parent.StringValue.Value; |
2 | Val = 'Hello World!' ; |
It's changing the Val
variable, but not the actual string value's. The solution to the problem's to overwrite the index in the table. For example, lets have 3 values in a table.
1 | local Dictionary = { Hello = 'no' , Beautiful = 'u' , World = 'hecker' } ; |
To overwrite the index, you simply set the index to a different value.
1 | local Dictionary = { Hello = 'no' , Beautiful = 'u' , World = 'hecker' } ; |
2 | Dictionary.World = 'nerd' ; -- Overwrites `World` from 'hecker' to 'nerd' |
3 | -- Note that that's one way to index a table. |
Please note that when there's no index prior in the table, it's going to set that new index.
So, in your case, you want to overwrite the indexes to the new values.
01 | local TableToMatchAccordingToIndex = { Cash = 0 , Money = 0 , ChaChing = 0 } ; |
02 | local PlayersData = { Cash = 123566 , Money = 2345 , ChaChing = 1231213 } ; |
03 |
04 |
05 | for Index, Value in pairs (PlayersData) do |
06 | -- You'll notice the use of square brackets; they're used to index the table, especially in cases like this. |
07 | TableToMatchAccordingToIndex [ Index ] = Value; -- Overwrites the index to the `PlayersData`'s value index |
08 | end |
09 |
10 |
11 | for Index, Value in pairs (TableToMatchAccordingToIndex) do |
12 | print (Index, Value); -- Cash 123566 Money 2345 ChaChing 1231213 |
13 | end |
Any questions? Feel free to ask. :) Hope this helped! :D
While this script is extremely questionable I have been able to fix your problem. The thing about tables is that if you want to change the value in a table then you have to do:
01 | local TableToChange = { V 1 = 0 ,V 2 = 0 } |
02 | local TableChanges = { V 1 = 10 ,V 2 = 25 } |
03 |
04 | for i,v in pairs (TableToChange) do |
05 | for k,d in pairs (TableChanges) do |
06 | if i = = k then |
07 | TableToChange [ i ] = TableChanges [ k ] --changes the value that is in the position I |
08 | end |
09 | end |
10 | end |
11 |
12 | for i,v in pairs (TableToChange) do |
13 | print (i,v) |
14 | end |
Be mindful of the fact that Roblox does not like porn games and so I recommend changing pazzah to cat if you know whats good for you