local Open = false local Joe = script.Parent.Parent.Close:GetChildren() local Bob = script.Parent.Parent.Open:GetChildren() function Click () if Open == false then if Joe.name == "Part" then Joe.Transparency = 1 Joe.CanCollide = false end if Joe.name == "Window" then Joe.Transparency = 1 Joe.CanCollide = false if Bob.name == "Part" then Bob.Transparency = 0 Bob.CanCollide = true end if Bob.name == "Window" then Bob.Transparency = 0.5 Bob.CanCollide = true end end Open = true elseif Open == true then if Joe.name == "Part" then Joe.Transparency = 0 Joe.CanCollide = true end if Joe.name == "Window" then Joe.Transparency = 0.5 Joe.CanCollide = true end if Bob.name == "Part" then Bob.Transparency = 1 Bob.CanCollide = false end if Bob.name == "Window" then Bob.Transparency = 1 Bob.CanCollide = false end Open = false end end script.Parent.ClickDetector.MouseClick:connect (Click)
I click the button and the output shows nothing, this script it also not working, first time trying the GetChildren() function so I hope that's the problem. The function is supposed to find two doors, both having two separate windows in them. When the button is clicked it's supposed to open the door.
The problem here is that the GetChildren function returns a read-only TABLE of the function. You cannot do script.Parent.Parent.Close:GetChildren().Transparency = 1
because it's not that simple. You have to use a for loop to go through each child in Close and perform the action as such.
local Open = false local Joe = script.Parent.Parent.Close:GetChildren() local Bob = script.Parent.Parent.Open:GetChildren() function Click () if Open == false then for _, child in pairs(Joe) do --I assume you are familiar with generic for loops if child.Name == "Part" then --Capitalize Name, it is the name of a property child.Transparency = 1 child.CanCollide = false elseif child.Name == "Window" then --Use elseif instead of multiple if statements child.Transparency = 1 child.CanCollide = false end for _, child in pairs(Bob) do if child.Name == "Part" then child.Transparency = 0 child.CanCollide = true elseif child.Name == "Window" then window.Transparency = 0.5 window.CanCollide = true end Open = true elseif Open == true then --You get the point by now end end script.Parent.ClickDetector.MouseClick:connect (Click)
If you are not familiar with generic for loops, check out this article on the Roblox Wiki for help. If you had any problems understanding these concepts, just ask me and I'll edit my response. I hope my answer was helpful! You can upvote and accept it if you thought so.