If not, can you tell me how I can fix it? I want it so that you can put it in the Workspace and anypart named Lava or Acid will change reflectance and transparency with respect to the script.
local p = "Lava, Acid" p.Transparency = 0.5 p.Reflectance = 0.5 wait(0.5) p.Transparency = 0.5 p.Reflectance = 0.2
Try using for loops
!
for i, v in pairs(Workspace:GetChildren()) do if v:IsA"BasePart" and v.Name == "Lava" or v.Name == "Acid" then v.Transparency = 0.5 v.Reflectance = 0.5 end end wait(0.5) for i, v in pairs(Workspace:GetChildren()) do if v:IsA"BasePart" and v.Name == "Lava" or v.Name == "Acid" then v.Transparency = 0.5 v.Reflectance = 0.2 end end
for loop
can be used to search through any object for it's children, making it excellent at searching objects with same name.
This will make script search through all the Workspace for a part named either "Lava" or "Acid". When it finds part/parts, it/they will change respectively to your likings.
There are two for loops
because the first one makes Reflectance of those part 0.5, and the second on turn the Reflectance to 0.2. If there was one loop and wait(0.5) was in the middle (see below), that would make it so it changes parts one by one, rather than every at once.
for i, v in pairs(Workspace:GetChildren()) do if v:IsA"BasePart" and v.Name == "Lava" or v.Name == "Acid" then v.Transparency = 0.5 v.Reflectance = 0.5 wait(0.5) v.Transparency = 0.5 v.Reflectance = 0.2 end end
Note: v:IsA"BasePart"
makes sure that it's a part, not script so you don't end up changing Reflectance of a script named Acid or Lava.
A more efficient way that you could do this, assuming that the number of Lava and Acid Part
s stays the same, is to first store them all in a table, like-so:
dangerousParts = {} --Store the dangerous parts, lava, acid, electric, poison, you name it... for _,v in pairs(workspace:GetChildren()) do if v.Name == "Lava" or v.Name == "Acid" then table.insert(dangerousParts,v) end end --This runs the 'animation' of the dangerousBricks in a loop, but you can change to run it however you like --Also notice that in the example you gave Transparency stayed the same the whole time, so no need to add that in too function SetReflectance(reflectance) for _,part in pairs(dangerousParts) do if part:IsA("BasePart") then part.Reflectance = reflectance end end end while wait(0.5) do SetReflectance(0.5) wait(0.5) SetReflectance(0.2) end
This answer avoids the problem in all the other answers (that have been posted up until I started writing) that it will adjust the transparency of each "dangerous part" one-by-one with a wait()
delay.
EDIT: Tiranin has a good answer too, now.
Try this instead
function AcidLava(part) part.Transparency = 0.5 part.Reflectance = 0.5 wait(0.5) part.Reflectance = 0.2 end for i, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Lava" or v.Name == "Acid" then AcidLava(v) end end