Basically, it's designed to make a door transparent and cancollide=false on click, then when it's clicked again, it goes cancollide = true and transparency = 0. Except that doesn't happen? You click a button for it to work, which is a part. The model, which is the door (model because it has multiple parts) is inside the button. The model is called yolo.
local hi = true function on() hi = true local found = script.Parent.yolo:GetChildren()for i = 1, #found do i.Transparency = 0 end local found = script.Parent.yolo:GetChildren() for i = 1, #found do i.CanCollide = true end end function off() end hi = false local found = script.Parent.yolo:GetChildren( )for i = 1, #found do i.Transparency = 0.5 end local found = script.Parent.yolo:GetChildren() for i = 1, #found do i.CanCollide = false end function onClicked() if hi == true then off() else on() end end script.Parent.ClickDetector.MouseClick:connect(onClicked) on()
Your for loops aren't setting the transparency of anything. You told it to loop the amount of times equal to the children in the model -- but that type of for loop wouldn't work for this situation. You want to use something like pairs
. Your 'off' function's syntax is also kind of off.
local hi = true function on() hi = true local found = script.Parent.yolo:GetChildren() for _,v in pairs (found) do -- No need to make two loops for the same thing. v.Transparency = 0 v.CanCollide = true end end function off() hi = false local found = script.Parent.yolo:GetChildren() for _,v in pairs (found) do v.Transparency = 0.5 v.CanCollide = false end end function onClicked() if hi then -- Also no need for '== true' for boolean variables, you can use just the variable for true. off() else on() end end script.Parent.ClickDetector.MouseClick:connect(onClicked) on()
Hope this helped.