Why does my code use only one part

pls help ,why my script only transparency on one part

local wind = script:WaitForChild("WindSteamModel"):Clone()
for i,v in pairs(wind:GetChildren()) do
					for i = 1 ,math.huge do
						v.Transparency = v.Transparency + 0.25


1 Like

You cannot use math.huge in a for statement.
Instead, Use for i=0, 1/0.25 do.

[quote=“dollychun, post:2, topic:854623”]
uhh its not work :ohmy:

Definitely not.

my problem its why my GetChildren Function get only 1 part

You’ll need to provide more context for us to be able to provide a solution.

Here’s some things which would help:

  • After running the place in Studio, provide a copy of the output so we can determine if and where an error occurs.

Here’s some things noted off the current information:

  • You clone the “WindStreamModel”, but you don’t seem to parent it. Is the problem not seeing the copied Instances at all, or merely not changing transparency?
    - As previously stated, using math.huge in the for loop is bad practice. Transparency can go from 0 - 1 as a decimal, so change math.huge to 0

EDIT: Apologies, there was an error in the above statement. The for loop is indeed incorrect, but you do not provide context on how fast you desire to change the transparency. Are you intending for the Parts to become fully transparent, or partially?

You can use math.huge though, however it would go make the for loop go to infinity and cause the transparency to increase beyond 1 to 0.25 * math.huge which is I believe… not what we are looking for as transparency should only be between 0 to 1.

Edit: Yeah this solution will cause all the instances :GetChildren() returns to simultaneously become transparent instead of one by one. The question is indeed a bit vague as @BleuPigs mentioned.

As for why the code uses only one part it is because of the wait(0.8) within the for loop which “pauses” or yields the entire script for 0.8 seconds as the code executes line by line from 1 to …as long as the script lasts.

To prevent the wait(0.8) from pausing the entire script the solution is to make “new” scripts in the form of new threads using a cool thing called coroutines to create a new “script” or thread so that the wait will not interupt the current script/thread

local wind = script:WaitForChild("WindSteamModel"):Clone()

--new "script" or precisely thread 
--makes the part slowly increase in transparency in increments of 0.25 until 1
local newThread = coroutine.wrap(function(part)
        part.Transparency = part.Transparency + 0.25
    until part.Transparency >= 1

--perform this script individually for each part
for i,BasePart in pairs(wind:GetChildren()) do

i changed my loop to
i = 0 , 1/0.25 do
and its work now