two things: 1. Use the correct node-name: "default:water_source" not "default:water" 2. you can shorten your function: local atleast_nodes_in_t = function(pos, search_distance, height, node_name, threshold) minp = {x = pos.x - search_distance, y = height, z = pos.z - search_distance} maxp = {x = pos...