Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

For loop with table?

Asked by 8 years ago

--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
0
what if theres no Player1 or Roblox ingame? e.e KoreanBBQ 301 — 8y
0
this isn't the entire script, the table is filled with real players magiccube3 115 — 8y
0
The contents of the table isn't the problem. magiccube3 115 — 8y
0
`print(#_G.realstats)` immediately before the loop -- what do you get? Most likely, you're not filling the table correctly BlueTaslem 18071 — 8y
View all comments (3 more)
0
http://i.imgur.com/LPj5g45.png As you can see, the table is set correctly according to the players. magiccube3 115 — 8y
0
As I said, "immediately before the loop". Don't edit your question with "problem solved" -- it's useful to archive the original. BlueTaslem 18071 — 8y
0
Oh, I'm sorry i read your comment to fast, I thought you meant i never filled it correctly at all. Also, re-editing question. magiccube3 115 — 8y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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.

Ad
Log in to vote
0
Answered by 8 years ago

Problem Solved.

Answer this question