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

Why does this for-loop not work?

Asked by 9 years ago

Once again having troubles with putting values into tables. This time it is an item that is going to be put in a table so that I can keep track of how many parts there are in there. Here is what I have:

bags = {}

trunk.Touched:connect(function(hit)
    if hit.Name == "MoneyBag" then
        local moneybag = hit
        print("yes")
        if moneybag then
            local money = moneybag:FindFirstChild("Money").Value
            print("funker")
            for _, moneybag in pairs(bags) do
                print("japp")
                if moneybag ~= bags then
                    table.insert(bags, moneybag)
                    totalmoney = totalmoney + money
                    print("no")
                end
            end
        end
    end
end)

Forgot to add the table in the first version, but there it is.

Thank you for your help (:

2
Where is your Table at? Also, I wouldn't use moneybag as a variable in line 7 because it is assigned something. You should have your Table already existing at first for this script. alphawolvess 1784 — 9y
0
What is 'bags'? I don't see any Variable named 'bags' anywhere, other than it being used in and inside the 'for' loop code block chunk, unless this is not the full script, and if that's the case, please include the FULL script/code. TheeDeathCaster 2368 — 9y
0
There's no point in using `:FindFirstChild` if you're going to go ahead and use `.` on it anyway. BlueTaslem 18071 — 9y
0
You didn't define bags in the script. yoshiegg6 176 — 9y

Answer this question