I’m trying to make animated water. I have 12 transparent meshparts that look like water and for every 0.1 seconds only few meshparts are visible while the rest are not.
local WaterChildren = script.Parent:GetChildren()
while wait(0.2) do
if WaterChildren.Name == "1" then
WaterChildren.Transparency = 0
wait()
end
end
For the first frame I want every meshpart under Water named “1” to become visible. It won’t work when I run the game. What am I doing wrong?
You should Use for
loops for this.
Example :
local WaterModel=script.Parent
for i, v in pairs(WaterModel:GetChildren()) do
if v:IsA("BasePart") and v.Name=="1" then end
v.Transparency=1 -- This Sets All the Water Parts named "1" To Transparent.
end
end
1 Like
This isn’t working. The script is trying to make all the children under Water transparent instead of all the meshparts under the Block’s.
The Script i gave was just an example, you can format it and use it as You want.
If you want to change ALL Meshparts Transparent you can Do
local WaterModel=script.Parent
for i, v in pairs(WaterModel:GetChildren()) do
if v:IsA("MeshPart") and v.Name=="1" then end
v.Transparency=1 -- This Sets All the Water Parts named "1" To Transparent.
end
end
While Sub2Wheez is correct that you should use for loops they are using GetChildren which is getting the Block models instead of the actual parts. Try doing script.Parent:GetDescendants()
instead of GetChildren
Your updated script would look something like:
local WaterModel = script.Parent
--GetDescendants gets all the children you could say, so its gets the children of the children
for Index, Value in pairs(WaterModel:GetDescendants()) do
--if its not a basepart the skip this iteration
if not Value:IsA("BasePart") then continue end
if Value.Name == "1" then
Value.Transparency = 0
else
Value.Transparency = 1
end
end
EDIT:
You can read more on GetDescendants here.
1 Like