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

:7: invalid argument #1 to 'insert' (table expected, got nil)?

Asked by 3 years ago

Hello! I've been working on a game and I cant figure out this problem with my lua code, I have tried to fix the code but I couldn't fix line 7. Heres the script:

blocks={}
seed=math.random(1,10000)/10001
local pos
local function makeblock(pos,block)
    table.insert(blocks,pos.X,{})
    table.insert(blocks[pos.X],pos.Y,{})
    table.insert(blocks[pos.X][pos.Y],pos.Z,{pos,Vector3.new(pos.X*2.5,pos.Y,pos.Z*2.5),block})
end
for i = 1,100 do
    for z = 1,100 do
        height = math.noise(i,z,seed)*30
        heightfit = math.floor(height/2.5)*2.5
        _=makeblock(Vector3.new(i,heightfit,z),"Stone")
        wait()
    end
end
spawn(function()
    while wait(3) do
        game.ReplicatedStorage.RemoteEvent:FireAllClients(blocks)
    end
end)
0
blocks[pos.X] = {} blocks[pos.X][pos.Y] = {} table.insert(blocks[pos.X][pos.Y],pos.Z,{pos,Vector3.new(pos.X*2.5,pos.Y,pos.Z*2.5),block}) Try this out for me InedibleGames 150 — 3y
0
Apparently blocks[pos.X][pos.Y] doesn't exist. Few questions: Is this original code, if not where did you find it? User#30567 0 — 3y

1 answer

Log in to vote
-1
Answered by 3 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

At the end of the seventh line, you finished it with a comma so replace the comma with a parenthesis.

0
that wouldn't do anything, it adds onto the following line. TheOnlySmarts 233 — 3y
Ad

Answer this question