Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

blocks[pos.X] = {}

blocks[pos.X][pos.Y] = {}

table.insert(blocks[pos.X][pos.Y],pos.Z,{pos,Vector3.new(pos.X2.5,pos.Y,pos.Z2.5),block})

Try this out for me

0

Apparently blocks[pos.X][pos.Y] doesn't exist. Few questions: Is this original code, if not where did you find it?

1 answer

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

1 comment

0

that wouldn't do anything, it adds onto the following line.

This discussion is preserved as it was. New answers, comments, and votes are closed.