Attempted to index number with transparency

snowfolder = workspace.SnowSystem
snowblocks = snowfolder.SnowBlocks:GetChildren()
enabled = snowfolder.enabled.Value

while enabled == true do
snow1 = math.random(#snowblocks)
snow2 = math.random(#snowblocks)
snow3 = math.random(#snowblocks)
snow4 = math.random(#snowblocks)
snow5 = math.random(#snowblocks)
if snow1.Transparency == 1 then
snow1.Transparency = 0
elseif snow2.Transparency == 1 then
snow2.Transparency = 0
elseif snow3.Transparency == 1 then
snow3.Transparency = 0
elseif snow4.Transparency == 1 then
snow4.Transparency = 0
elseif snow5.Transparency == 1 then
snow5.Transparency = 0
wait(5)
end
end

Instead of manually changing each snow you can just loop through the snow parts and change their transparency in 1 go. Make sure they’re sorted in the workspace first, like putting them inside a folder.

while enabled == true do
    for i, snow in pairs(example:GetChildren()) do -- "example" can be the folder that has all the snow parts
      if snow.Transparency == 1 then
           snow.Transparency = 0 
      end 
   end
  wait(5)
end

Not sure what snow1 = math.random(#snowblocks) does

i want it so its not all snow transparent at once that was deciding a random part of snow in children instead of selecting it all

So you want the transparency to be set to a random number, and then checked if it’s 1?

so the snow 1 and 5 was just determining a random snow piece from the flder

So what is it you want exactly because i’m kinda confused?

so the script selects a random piece of snwo from the folder every say 15 seconds and sets it to transparency 0 the snow 1 math random was selecting a random piece from the folder named Snow

while enabled == true do
      SelectedSnow = snowblocks[math.random(#snowblocks)]
      if SelectedSnow.Transparency == 0 then 
         SelectedSnow.Transparency = 1
      end
      task.wait(15)
end

Like this?

ye then it loops and does it for a different snow blocxk every time

except im getting index nil number with transparency from this to

Instead of math.random(#snowblocks) you need snowblocks[math.random(#snowblocks)]

while enabled == true do
      SelectedSnow = snowblocks[math.random(#snowblocks)]
      if SelectedSnow.Transparency == 0 then 
         SelectedSnow.Transparency = 1
      else continue end
      task.wait(15)
end

You can just add a continue if the selectedsnow is already transparent

thank you so much really appreciated

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.