I'm trying to code tetris, and I'm stumped because this code I have keeps on throwing errors. I have the function GetPartsAtPosition() checking if something is below the part that is going to move, to check if it can move or not. In Move(), I have it doing a loop through the pieces of the tetromino and using GetPartsAtPosition() on each of the pieces. It keeps on spouting random errors like Argument 1 missing or nil for the toucher variable definition line. With some pieces, they go down to the bottom and then the following pieces that spawn clump up at the top. With others, the clumping starts immediately. Here's a snippet of the code:
local function GetPartsAtPosition(Position :Vector3)local Touching = workspace:GetPartBoundsInBox(CFrame.new(Position), Vector3.one*0.1, OverlapParams.new())for i = 1, #Touching-1 do local toucher = workspace.Pieces:WaitForChild(Touching[i],1) if toucher then if toucher.Position ~= Position then table.remove(Touching, i) end else table.remove(Touching, i) endendreturn Touching or {}
end
local function Move(piece:Instance)
wait(tickspeed*(level/3))local parts = piece:GetDescendants()local canMove = truefor i,v in pairs(parts) dolocal PartsAtPosition = GetPartsAtPosition(Vector3.new(v.Position.X+1,1,v.Position.Z))if #PartsAtPosition >= 1 then print('Part detected!') canMove = falseelse print('No parts at that position') endendfor i,v in pairs(parts) do if v.Position.X >= -13 then canMove = false endendif canMove then for i,v in pairs(parts) do v.Position = v.Position + Vector3.new(1,0,0) endendreturn canMove
end
Any help would be appreciated. Also, the piece moving down on the Tetris board would be an increase in the X value of the part.