Why is half of my function not executing?

I am making a rollercoaster control panel system and I have come across a problem. I am trying to make it look like the restraints move but the ‘RestraintsOpen’ part of the script doesn’t work. The “RestraintsLocked” part does execute meaning they disappear but the ‘RestraintsOpen’ part still stays invisible. I would be grateful if anyone could help, and I know there are ways to do this with less code but I wanted it to be simple.

Workspace (Yes it is the correct parts selected in the code):
image

Code:

function click()
	workspace.RedRunner.Train1.RestraintsLocked.one.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.two.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.three.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.four.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.five.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.six.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.seven.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.eight.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.nine.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.ten.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.eleven.Transparency = 1
	workspace.RedRunner.Train1.RestraintsLocked.twelve.Transparency = 1
	workspace.RedRunner.Train1.RestraintsOpen.one.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.two.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.three.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.four.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.five.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.six.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.seven.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.eight.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.nine.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.ten.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.eleven.Transparency = 0
	workspace.RedRunner.Train1.RestraintsOpen.twelve.Transparency = 0
end
script.Parent.MouseClick:Connect(click)
2 Likes

One thing I can imagine that is causing the issue that (if the path to the object is correct) you have to make sure that the parts are anchored. If that is not the solution, then you have to provide more clarity to the problem. Show how you have RestraintsLocked sorted in your workspace as opposed to the RestraintsOpen to see if there are differences between the two that is causing the issue.

P.S.

I suggest changing the way you call for parts. A much more appropriate way of doing so would be the following;

local partsRestraintsLocked = game.Workspace.Redrunner.Train1.RestraintsLocked:GetChildren()
local partsRestraintsOpen = game.Workspace.Redrunner.Train1.RestraintsOpen:GetChildren()

local function click()
	for i, part in partsRestraintsLocked do
		part.Transparency = 1
	end
	
	for i, part in partsRestraintsOpen do
		part.Transparency = 0
	end
end)

In contrary to what you said, doing it this way is much simpler than what you have originally down.

2 Likes

Thank you! I didn’t realise they weren’t anchored. Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.