local rnd = math.random(1, #cells[dim])
"attempt to get length of field '?' (a nil value)" means you've tried to get the length (# operator) of a nil value (cells[dim]), which means there is no value in the cells table with the index corresponding to the value of dim. Your if-check sets the value of dim to the value of defaultCells, 174, but cells[174] also doesn't exist. Only cells[10] exists.
cells = {
--[Int ID] = {{Cellák pos}}
[10] = {215.36199951172, 108.91190338135, 1000.9522705078, 180},
[10] = {219.84390258789, 108.5353012085, 1000.9569702148, 180},
[10] = {223.37170410156, 107.92459869385, 1000.8811035156, 180},
[10] = {227.17649841309, 107.85209655762, 1000.6198120117, 180},
}
By the way, you can't have multiple values under one index. The table above, after construction, is equivalent to
cells = {
[10] = {227.17649841309, 107.85209655762, 1000.6198120117, 180}
}
that is, every line starting with [10] = overrides the previous line starting with [10] =
You probably wanted something like
cells = {
--[Int ID] = { [Dim ID] = { {Cellák pos}, {Cellák pos}, ... }, }
[10] = { -- in interior 10
[174] = { -- in dimension 174
{215.36199951172, 108.91190338135, 1000.9522705078, 180}, -- first cell in int 10 dim 174
{219.84390258789, 108.5353012085, 1000.9569702148, 180}, -- second cell in int 10 dim 174
{223.37170410156, 107.92459869385, 1000.8811035156, 180}, -- third cell in int 10 dim 174
{227.17649841309, 107.85209655762, 1000.6198120117, 180}, -- fourth cell in int 10 dim 174
},
},
}
-- ...
local int = getElementInterior(player)
if int == 0 or not cells[int] then -- if interior is 0 or there are no cells in the interior
int = defaultInt -- set int to default (10)
end
local dim = getElementDimension(player)
if not cells[int][dim] then -- if there are no cells in that interior and dimension
dim = defaultCells -- set dimension to default (174)
end
local rnd = math.random(1, #cells[int][dim]) -- pick a random cell from 1 to however many there are for that interior and dimension
local randomCell = cells[int][dim][rnd] -- index the cells table for the random cell
-- ...