I'm working on a switch track doohickey, and I got the button to work by if you click it, it will change its BoolValue Child, Curve to true, then this script, if the BoolValue is true, it will do a function, but It won't work. Please help.
curve = script.Parent.Button.Script.Curve
track1 = script.Parent.Turn.Turn2.M2
track2 = script.Parent.Turn.Turn2.M3
un1 = script.Parent.Straight.yep
un2 = script.Parent.Straight.yep2
while true do
if curve.Value == true then
changeTrackPos()
else
wait()
end
end
function changeTrackPos()
print('positive rate')
if un1.CanCollide and un2.CanCollide == false then
un1.CanCollide = true
un2.CanCollide = true
un1.Transparency = 0
un2.Transparency = 0
else
un1.CanCollide = false
un2.CanCollide = false
un1.Transparency = 0.5
un2.Transparency = 0.5
local children1 = track1:GetChildren()
for i = 1, #children1 do
if children1[i].CanCollide == false then
children1[i].CanCollide = true
children1[i].Transparency = 1
else
children1[i].CanCollide = false
children1[i].Transparency = 0.5
local children2 = track2:GetChildren()
for a = 2, #children2 do
if children2[a].CanCollide == false then
children2[a].CanCollide = true
children2[a].Transparency = 1
else
children2[a].CanCollide = false
children2[a].Transparency = 0.5
end
end
end
end
end
end

1 comment
The function ChangeTrackPos is called on line 9, but is not defined until line 16 and therefore will not run. If you simply move the ChangeTrackPos function up above the whole loop, it should fix the problem.