Hi,
I'm making a gate that when you click it all the parts in the gate model disappear. This works, however throws errors out when it gets to the ClickDetector and then doesn't work correctly.
However, I don't see why it should? I've made it so it checks the ClassName of each child to ensure the correct things are happening to the correct parts. I'm a bit stumped.
Here's the code:
local function CloseClose() for i,v in pairs(script.Parent.Closed:GetChildren()) do if v.ClassName=='Part' or 'UnionOperation' then v.Transparency=1 v.CanCollide=false else v.MaxActivationDistance=0 end end end
Before you fix your problem you must first know truthy values and falsey values.
Truthy values in Lua are anything that is not false or nil. Strings, numbers and tables are examples of truthy values.
Falsey values are just false or nil.
or
, and
, not
are all logical operators
.
x or y
evaluates to x
if x
is truthy, y
otherwise.
x and y
evaluates to x
if x
is falsey, y
otherwise
not x
evaluates to true
if x
is falsey, false
otherwise.
Change line 3 to if v:IsA("BasePart") then
BasePart is the superclass of all the part classes. Part, UnionOperation, TrussPart, and ect. all inherit this class.
I'm assuming this problem is coming from this v.ClassName=='Part' or 'UnionOperation'
, that's not how the or
operator work, you need to do it like this
if v.ClassName=='Part' or v.ClassName =='UnionOperation' then
You can also use :IsA() which is cooler
if v:IsA("Part") then