I'm trying to create a script where it gets the parts and either makes them cancollide or not. There are parts called open and parts called closed.
local close = script.Parent.Parent.SwitchRail.Switch:GetChildren("Close")
local open = script.Parent.Parent.SwitchRail.Switch:GetChildren("Open")
print("WAZZAP")
function onTouched(part)
if part.Name == "ARS" then --Change this to the name of the correct part that trips the sensor
if part.Value.Value == 1 then
script.Parent.Parent.LeftSignal.JCT1.SurfaceGui.Whi.ImageTransparency = 0
script.Parent.Parent.LeftSignal.JCT2.SurfaceGui.Whi.ImageTransparency = 0
script.Parent.Parent.LeftSignal.JCT3.SurfaceGui.Whi.ImageTransparency = 0
script.Parent.Parent.LeftSignal.JCT4.SurfaceGui.Whi.ImageTransparency = 0
for i, v in pairs(close) do
v.Transparency = 0.5
v.CanCollide = false
i.Transparency = 0
i.CanCollide = true
end
else
for i, v in pairs(open) do
v.Transparency = 0.5
v.CanCollide = false
i.Transparency = 0
i.CanCollide = true
end
end
end
end
script.Parent.Touched:connect(onTouched)

4 comments
:GetChildren() dont take arguments?
?
indent your code so it’s more legible maybe?
indent your code so it’s more legible maybe?