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

Would this script work?

Asked by 10 years ago

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

0
when you say `local p = "Lava, Acid"` All your doing is defining p as a string that is "Lava,Acid". If you want to change everything in the workspace, you need to use a for loop. soaprocks2 75 — 10y
0
Ah, okay. TheRings0fSaturn 28 — 10y

3 answers

Log in to vote
0
Answered by
Tiranin 45
10 years ago

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.

1
You described having two separate for loops, but there is only one in your code example - it will go through each piece one by one just like every other answer so far. duckwit 1404 — 10y
0
Oh right, silly me. I forgot to add the other loop! Tiranin 45 — 10y
0
Edited. Thanks agin for pointing it out! Tiranin 45 — 10y
Ad
Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
10 years ago

A more efficient way that you could do this, assuming that the number of Lava and Acid Parts 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.

Log in to vote
-2
Answered by 10 years ago

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
0
This will also pause (yield) for each part, adjusting them slowly one by one instead of simultaneously. duckwit 1404 — 10y

Answer this question