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

Why is this error called?

Asked by
Mowblow 117
9 years ago
local unions = {}

function DefineForUnion() -- 
    local things = game.Workspace:GetChildren()
    for thing in #things do
        if thing.className == "UnionOperation" then
            table.insert(thing)
        end
    end
end

It gives the error: "attempted to call a number value".

Any suggestions?

1 answer

Log in to vote
1
Answered by 9 years ago

You have a couple thing wrong.

table.insert takes 2 arguments, the table and thing you want to insert.

example:

local Table = {}

table.insert(Table,"Hello")

The for loop you were using is not the best for tables, use a in pairs loop instead.

Here is a fixed version of your code:

local unions = {}

function DefineForUnion() -- 
local things = game.Workspace:GetChildren()
    for i , v in pairs (things) do
        if v.className == "UnionOperation" then
            table.insert(unions,v)
        end
    end
end
0
Thanks, Man! Mowblow 117 — 9y
Ad

Answer this question