--Problem Solved Note that in-game the table is filled with real player names. Unfixed V
tablename = {"Player1", 100, "Player2", 200} for i = 1,#tablename, 2 do game.Players[tablename[i]].leaderstats.money.Value = tablename[i+1] end
Fixed V
tablename = {"Player1", 100, "Player2", 200} for i = 1,#tablename, 2 do if game.Players[_G.realstats[i]].leaderstats.money then -- don't break yourself mr.script game.Players[tablename[i]].leaderstats.money.Value = tablename[i+1] end end
Learn to debug!
If something appears to do nothing, think of the reasons why that might be.
You were debugging by printing _G.realstats
in the console -- but all sorts of things could happen between there and the code you think is running (in particular, the code you think is running could not be happening at all)
This is also an excellent argument against using _G
. You should use functions or module scripts to fill values, not just hope someone else has plopped them in. Explicit communication is much better.
print(#_G.realstats)
immediately before it's use guarantees you're seeing the right thing, and then you can begin to investigate why it might be that you get 0
.