What I am trying to do is have a script that can detect an unlimited^ number of switches inside of a model and connect them to a function when clicked, I have the following script, but it returns the error of Attempt to connect failed: Passed value is not a function
^ Not exactly unlimited but quite high
repeat wait() until workspace.PowerSubstation
local radian = 0.0174533
local degree = 60
local totalr = degree * radian
if totalr <= 1.0470 or totalr >= 1.0474 then
warn'Something went wrong!'
end
local function switch(switch)
if not switch.Type.Value then
switch.Enabled.Transparency = 0
switch.Transparency = 1
switch.Type.Value = not switch.Type.Value
script["Enabled Switches"].Value = script["Enabled Switches"].Value + 1
elseif switch.Type.Value then
switch.Enabled.Transparency = 1
switch.Transparency = 0
switch.Type.Value = not switch.Type.Value
script["Enabled Switches"].Value = script["Enabled Switches"].Value - 1
end
print(script["Enabled Switches"].Value)
end
for i,v in pairs(script.Parent.Switches:GetChildren()) do
v.ClickDetector.MouseClick:connect(switch(v))
end
Any help would be appreciated, thank you!
TheHospitalDev

2 comments
You know about the math.rad(degrees) function, right? You don't need your own conversion.
Line 15 can just be "else" by itself because bool values only have 2 values.