Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

4 comments

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.

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

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.