Hi Roblox!,
Im in the works of my new game called ____________. I am currently making a You win text label that tweens down when all the parts in a folder are transparent, Can you help me fix it. (PS: There are no errors in the output)
Code:
local TransparentParts = game.Workspace.Devs:GetChildren()
if TransparentParts.Transparency == 1 then
script.Parent:TweenPosition(UDim2.new(0.5,0,0.5,0))
end
Can you help?
Thanks for reading, have a great rest of your day!
It is because you tried to check the transparency of an array of parts (GetChildren()). You should rename one of the main parts to something different than the others and do if workspace.Devs.partName.Transparency == 1 then…
GetChildren returns a table without any “Transparency” value, try looping through the children instead.
local TransparentParts = game.Workspace.Devs
for _, part in pairs(TransparentParts:GetChildren()) do
if part:IsA("BasePart") and part.Transparency == 1 then
script.Parent:TweenPosition(UDim2.new(0.5,0,0.5,0))
break
end
end
As of now, this is only running once so it cannot detect when it is changed. You could use a part.Changed event to detect when the part has been changed or you can just put it in a while loop.
Event example:
for i, v in pairs(game.Workspace.Devs:GetChildren()) do
if v.Transparency == 1 then
script.Parent:TweenPosition(UDim2.new(0.5,0,0.5,0))
end
end
While loop example:
local TransparentParts = game.Workspace.Devs:GetChildren()
while wait() do
for i, v in pairs(TransparentParts) do
if v.Transparency == 1 then
script.Parent:TweenPosition(UDim2.new(0.5,0,0.5,0))
end
end
end
local TransparentParts = game.Workspace.Devs:GetChildren()
while wait() do
local count = 0
for i, v in pairs(TransparentParts) do
if v.Transparency == 1 then
count = count + 1
end
if count == #TransparentParts then
script.Parent:TweenPosition(UDim2.new(0.5,0,0.5,0))
end
end
end