local TableToMatchAccordingToIndex = {Cash = 0, Money = 0, ChaChing = 0} local PlayersData = {Cash = 123566, Money = 2345, ChaChing = 1231213} for i,v in pairs(TableToMatchAccordingToIndex) do for k,d in pairs(PlayersData) do if i == k then v = d end end end for i,v in pairs(TableToMatchAccordingToIndex) do -- I wanted this to print Cash = 1213566 Money 2345 and ChaChing 1231213 print(i,v) end
The problem is because you're changing the v
variable when you want to overwrite the index. This is the equivalent.
local Val = script.Parent.StringValue.Value; 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.
local Dictionary = {Hello = 'no', Beautiful = 'u', World = 'hecker'};
To overwrite the index, you simply set the index to a different value.
local Dictionary = {Hello = 'no', Beautiful = 'u', World = 'hecker'}; Dictionary.World = 'nerd'; -- Overwrites `World` from 'hecker' to 'nerd' -- 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.
local TableToMatchAccordingToIndex = {Cash = 0, Money = 0, ChaChing = 0}; local PlayersData = {Cash = 123566, Money = 2345, ChaChing = 1231213}; for Index, Value in pairs(PlayersData) do -- You'll notice the use of square brackets; they're used to index the table, especially in cases like this. TableToMatchAccordingToIndex[Index] = Value; -- Overwrites the index to the `PlayersData`'s value index end for Index, Value in pairs(TableToMatchAccordingToIndex) do print(Index, Value); -- Cash 123566 Money 2345 ChaChing 1231213 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:
local TableToChange = {V1 = 0,V2 = 0} local TableChanges = {V1 = 10,V2 = 25} for i,v in pairs(TableToChange) do for k,d in pairs(TableChanges) do if i == k then TableToChange[i] = TableChanges[k] --changes the value that is in the position I end end end for i,v in pairs(TableToChange) do print(i,v) 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