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

How do I make it so that I don't have to keep on adding Or's when there is something no?

Asked by
vh_ft -5
6 years ago
Edited 6 years ago

So basically I want the script to get of all the children under the parent of this object but not get the object that is the script.Parent of this script and check if the BackgroundTransparency is 0

local Other = script.Parent.Bubbly or script.Parent.Superhero or script.Parent.Hi or script.Parent.Bo
if Other.BackgroundTransparency == 0 then
    Other.BackgroundTransparency = 1
    game.Players.LocalPlayer.Character.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id=656118852"
end

1 answer

Log in to vote
1
Answered by
natsaa 5
6 years ago
Edited 6 years ago

You can use a for statement, combined with getChildren() to cycle through the children and do this.

local others = script.Parent:GetChildren()
for i,v in pairs(others) do
    if  v:IsA("GuiObject") and v.BackgroundTransparency == 0 then
        v.BackgroundTransparency = 1
        game.Players.LocalPlayer.Character.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id=656118852" -- I don't understand the purpose of this (especially when checking several items or looping), but I left it here just in case it was important
    end
end
1
You need to make sure that v ~= script *before* checking the BackgroundTransparency. Alternatively, perform v:IsA("GuiObject") to ensure that 'v' has 'BackgroundTransparency'. Line 5 can certainly go outside the for loop. chess123mate 5873 — 6y
0
Ah, it was late at night. I modified the if statement to utilize a short-circuit to check if v is a GuiObject before checking the transparency. Also, I didn't understand if he wanted line 5 to execute only when the if statement was true, or what- so I left it there to sort of maintain the same format as OP, while at the same time showing the way to answer his issue. Thanks for your input btw natsaa 5 — 6y
0
If you use 2 checks on the same if statement, you will never know what will run first. Wish they added a way to tell the script what should be checked first, though. hiimgoodpack 2009 — 6y
0
Actually, an if statement reads it left to right, that's why I checked if it was a GuiObject first. Try looking into "short-circuit evaluation", and that'll give you a good idea. natsaa 5 — 6y
Ad

Answer this question