Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my model not fading all at once? I want it to fade from 0.1 - 1 Transparency but animated!

Asked by 9 years ago
model = game.Workspace.TARDIS:GetChildren()

for i, v in pairs(model) do
for i = 0, 0.01, 1 do -- I think this is the problem?
i.Transparency = 1
end
end

1 answer

Log in to vote
0
Answered by 9 years ago

Hmm, there is a few problems with your code; Line 4: i is being used twice, and can mess up your script when running. Line 5: i.Transparency = 1? You are attempting to use index i as an identifier for the Child, when it is supposed to be an identifier for a Number Value/Identifier. Let me explain;

model = game.Workspace.TARDIS:GetChildren() --Why is this necessary? And what is 'TARDIS' is not existant at the time of execution?

for i, v in pairs(model) do --Correct
for i = 0, 0.01, 1 do --Correct, this is where one of the problems lye.
i.Transparency = 1 --Identifier 'i' is being used to identify the current Child being looped through?
end
end

As I have pointed out, there are three problems in your code, however, this can be fixed by using the WaitForChild method, fixing up the for loop, and fixing the identifier for the for loop, now, let's fix up your code;

local model = game.Workspace:WaitForChild("TARDIS") --Identifier 'model' is specifying the Child 'TARDIS' when it is existant; This will repeat waiting until Child 'TARDIS' is existant within 'game.Workspace', and will identify it when existant

for i,v in pairs(model:GetChildren()) do --Why not put 'GetChildren' right here? You may use identifier 'model' for another purpose in another code; The 'GetChildren' method creates a table of the current Children within the Parent [Parent:GetChildren()]
if v and v:IsA("BasePart") then --Another thing I forgot to mention earlier; What if the object is not a 'BasePart' type instance, or if the 'BasePart' type instance is not existant?
coroutine.wrap(function() --EDIT: The 'coroutine.wrap' function will all the thread of code to run without pausing the code
for x = 0, 1, 0.01 do --Now, 'x' is now identifying the 'Number' that is currently being used;
v.Transparency = x --'v' is the identifier for the Child; Changes the 'BasePart' type instances 'Transparency' to identifier 'x''s Number until it is equal to one
wait(.1) --Why not add a 'wait' to make the effect more real? Without the 'wait', it would automatically become Transparent
end --Ends the code block for the 'for' loop
end)() --Ends the code block for the 'coroutine'
end --Ends the code block for the 'if' statement
end --Ends the code block for the 'for' loop

Hope this helped, and sorry if I did not give a good explanation!

0
Haha! It's alright man. :) I'm really glad my Answer helped you out. :) I try to always make sure my Explanations make sense, as it sometimes confuses people. XD TheeDeathCaster 2368 — 9y
0
Oops I accidentally removed my message but you get it anyways. Wait, the script isn't working!!! Something is wrong. Can you fix it please? iDoctorW 0 — 9y
0
What is not working? Also, do you have any Output? If you do, please include it. TheeDeathCaster 2368 — 9y
0
ok let me see iDoctorW 0 — 9y
View all comments (5 more)
0
The output does not say anything. Btw in the TARDIS it has alot of parts iDoctorW 0 — 9y
0
I see, I'll edit my answer. TheeDeathCaster 2368 — 9y
1
You have your for loop wrong. Starting,Ending,Increment NotsoPenguin 705 — 9y
0
Notso is correct. 'for variable = startNumber, endNumber, increment do' is the correct format. Perci1 4988 — 9y
0
Sorry, I haven't used a 'for i = Number, Number, Number do end' loop for a while now, I'll edit my answer shortly. TheeDeathCaster 2368 — 9y
Ad

Answer this question