I’m still a beginner. The basic problem is trying to make a part loop through varying transparency values: 0, 0.1, 0.2…1, repeat over and over. I have a part in the workspace with a script inserted. The script below is what I’m using to change the transparency of the part. The loop isn’t repeating. In game play, the transparency only changes once from 0 to 0.1, then nothing. Can you point out my coding flaw for why this isn’t repeating? Thank you!
local glass = script.Parent
while true do
if glass.Transparency == 1 then
glass.Transparency = 0
elseif glass.Transparency == 0.9 then
glass.Transparency = 1
elseif glass.Transparency == 0.8 then
glass.Transparency = 0.9
elseif glass.Transparency == 0.7 then
glass.Transparency = 0.8
elseif glass.Transparency == 0.6 then
glass.Transparency = 0.7
elseif glass.Transparency == 0.5 then
glass.Transparency = 0.6
elseif glass.Transparency == 0.4 then
glass.Transparency = 0.5
elseif glass.Transparency == 0.3 then
glass.Transparency = 0.4
elseif glass.Transparency == 0.2 then
glass.Transparency = 0.3
elseif glass.Transparency == 0.1 then
glass.Transparency = 0.2
elseif glass.Transparency == 0 then
glass.Transparency = 0.1
print("Looped worked")
end
wait(.1)
while true do
for i = 0,1,.1 do
glass.Transparency = i
wait(.1)
end
end
I am sure you’ve felt like writing that many if statements is impractical, ha.
To answer your question though, the loop is not repeating because after it runs through once, all of the if statements will be false. You could fix this by setting the transparency to 1 at the end of the loop again.
EDIT: Not to mention your wait is outside of the loop, which means it will time out. Make sure to put that inside the loop.
Thanks for the input. Using the suggestion of the for loop made it work perfectly. So simple in the end. I did so much unnecessary work typing out all those lines.
Let me take this to the next level. Let’s say I have 3 parts in a folder. I want to use 1 script to change the transparency of all 3 of those parts. I’ve written the script below, thinking it would affect all the parts, but it’s only changing the transparency of 1 of the parts. I’m assuming something is missing to allow all parts to be affected independently. Here is my attempted script. I could write a script for each part, but that would be excessive. Any thoughts?
local glassTable = script.Parent.GlassFolder:GetChildren()
for _, glass in pairs(glassTable) do
while true do
for i = 0,1,.1 do
glass.Transparency = i
wait(.1)
end
end
end
In some way i fixed your script i put while true do at the third line to see what happened and it worked but it goes like this way
local glassfolder = game.Workspace.GlassFolder:GetChildren()
while true do
for _,v in pairs(glassfolder) do
for i = 0,1,0.1 do
v.Transparency = i
wait(0.1)
end
end
end