im attempting to make clouds/waves with perlin Nosie and my in pairs only affects one part for some reason and i cannot figure out why
my code:
local X = 100
local Z = 100
local g = {}
yscale = 5
local seed = math.random(-100000,100000)
local tab = {}
game:GetService('RunService').Heartbeat:Connect(function()
seed = math.random(-100000,100000)
end)
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(1,1,1)
p.Position = Vector3.new(x,0,z)
end
end
while game:GetService("RunService").Heartbeat:Wait() do
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 _,v in pairs(tab) do
for x = 1, X do
for z = 1, Z do
v.Transparency = g[x][z]
v.Name = "Nil" -- Self Debugging
wait()
end
end
end
end
Try merging your two heartbeat loops into 1, and see if that changes anything (probably wont). But do this to clean up the code and find the issue faster
Try applying a color to each part at the beginning of the pairs loop just to see if it correctly loops through each part.
Referring to
for _,v in pairs(tab) do
v.Color3 = Color3.fromRGB(3, 252, 44)
for x = 1, X do
for z = 1, Z do
v.Transparency = g[x][z]
v.Name = "Nil" -- Self Debugging
wait()
end
end
end
The reason I am saying that you add it to the beginning is because it won’t be affected by the other for loops that happen in between (that set transparency). That way, if only one part changes color, it means that all 1000 parts in the tabs table are either the same part or duplicates of one.
Also, why are you looping through every transparency on each value? I could be wrong, but wouldn’t it be best if you just used their position as X and Z? I could be wrong, but I feel as if it has something to do with the fact that you loop through every transparency possible for every part that has been created.
while game:GetService("RunService").Heartbeat:Wait() do
...
for _,v in pairs(tab) do
print(_)
for x = 1, X do
for z = 1, Z do
v.Transparency = g[x][z]
v.Name = "Nil" -- Self Debugging
wait()
end
end
end
end
Is: "For every part v in tab,
Iterate through x 100 times
Iterate through z 100 times
Change v’s transparency to g[x][z]
So basically, you change v’s transparency 10,000 times. Then you do that to part 2. And part 3. And so on.
I think you want to instead find some way to iterate through each part and extract the proper transparency value from there.
local X = 100
local Z = 100
local g = {}
yscale = 5
local seed = math.random(-100000,100000)
local tab = {}
game:GetService('RunService').Heartbeat:Connect(function()
seed = math.random(-100000,100000)
end)
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(1,1,1)
p.Position = Vector3.new(x,0,z)
end
end
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
while game:GetService("RunService").Heartbeat:Wait() do
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
end
I tried to implement from your description… is this not what you’re going for?
I think if you want shifting clouds, you need to keep the seed constant (otherwise you’re just changing the generation of clouds). Are you wanting them to wrap around or just go “off screen”?