In pairs not working properly

Sure! :slight_smile:

The code for the scrolling-effect is:

local PART_SIZE = 1
local X = 100
local Z = 100
local g = {}
yscale = 5
local seed = 1
local tab = {}



for x = 1, X do
	g[x]= {}
	for z = 1, Z do
		g[x][z] = math.noise(x/20, z/20,seed,-seed) * yscale 
	end
end


for x = 1, X do
	for z = 1, Z do
		local ypos = g[x][z]
		p = Instance.new('Part')
		table.insert(tab,p)
		p.Parent = workspace
		p.Transparency = g[x][z]
		p.Anchored = true
		p.Size = Vector3.new(PART_SIZE,PART_SIZE,PART_SIZE)
		p.Position = Vector3.new(x*PART_SIZE,0,z*PART_SIZE)
	end
end

local offset = 0
local offset_counter = 0

function getPlaceFromIndex(index)
	local z = ((offset + ((index - 1) % (Z) + 1)) % Z) + 1 -- Should produce something between 0 and 99
	local x = math.ceil(index / X) -- Should produce something between 0 and 99
	return g[x][z]
end

while game:GetService("RunService").Heartbeat:Wait() do
	offset_counter=(offset_counter+1) % 2
	if offset_counter == 0 then
		for x = 1, X do
			g[x]= {}
			for z = 1, Z do
				g[x][z] = math.noise(x/10, z/10,seed,-seed) * yscale 
			end
		end
		for i,v in pairs(tab) do
			local transparency = getPlaceFromIndex(i)
			v.Transparency = transparency
		end	
		offset = (offset+1) % Z
	end
end

I think this might describe the effect you’re talking about? I’m imagining “breathing” clouds, as it were…

local PART_SIZE = 2
local GRID_SIZE = 50 -- Bigger values -> bigger lag
local MAX_Y = 10 -- Determines the maximum sharpness of the noise
local SPEED_OF_BREATHING = 0.5 -- Determines how quickly the fading in / fading out occurs

local X = GRID_SIZE
local Z = GRID_SIZE

local g = {}
local yscale = MAX_Y
local seed = math.random(-1000000,1000000)
local tab = {}


function getPlaceFromIndex(index)
	local z = (index - 1) % (Z) + 1 -- Should produce something between 0 and 99
	local x = math.ceil(index / X) -- Should produce something between 0 and 99
	return g[x][z]
end

function set_y()
	for x = 1, X do
		g[x]= {}
		for z = 1, Z do
			g[x][z] = math.noise(x/10, z/10,seed,-seed) * yscale 
		end
	end
end



set_y()
for x = 1, X do
	for z = 1, Z do
		local ypos = g[x][z]
		p = Instance.new('Part')
		table.insert(tab,p)
		p.Parent = workspace
		p.Transparency = g[x][z]
		p.Anchored = true
		p.CastShadow = false
		p.CanCollide = false
		p.CanQuery = false
		p.CanTouch = false
		p.Size = Vector3.new(PART_SIZE,PART_SIZE,PART_SIZE)
		p.Position = Vector3.new(x*PART_SIZE,0,z*PART_SIZE)
	end
end

local angle = 1
while game:GetService("RunService").Heartbeat:Wait() do
	angle = (angle+SPEED_OF_BREATHING)%360
	yscale = 1 + (math.sin(math.rad(angle))) * (MAX_Y / 2)
	set_y()
	for i,v in pairs(tab) do
		local transparency = getPlaceFromIndex(i)
		v.Transparency = transparency
	end	
end