Alternate version of working function does not work

Put simply, I’m trying to update my train traffic signal system and it has been working fine.

However, upon modifying an existing function to be formatted slightly differently so I could add on to it, it just stops working entirely.

I don’t spot any issues with the code, though I may be overlooking something. I added print statements to test what runs, only to find out that none of them print (besides the “child added” print occurring at start up because of the TouchInterest instance).

Please let me know if there’s something I’m doing wrong here!

Code: (comment is old function, new function is above)

			--*GT1
			
			local function Countdown()
				print("count down 2")
				task.wait(0.1)
				if (child.PrevSensor.Value:FindFirstChild("OccupiedBy") ~= nil) and (child.TimerActive.Value == true) then
					print("yea")
					child.Countdown.Value = child.TimerLength.Value
				end
			end
			child.PrevSensor.Value.ChildAdded:Connect(function(added)
				print("child added")
				if added.Name == "OccupiedBy" then
					print("count down 1")
					Countdown()
				end
			end)
			child.TimerActive:GetPropertyChangedSignal("Value"):Connect(Countdown)
			
			--[[child.PrevSensor.Value.ChildAdded:Connect(function(added)
				task.wait(0.1)
				if (added.Name == "OccupiedBy") and (child.TimerActive.Value == true) then
					child.Countdown.Value = child.TimerLength.Value
				end
			end)]]

I can’t see any difference that would matter between the two. You could put in a breakpoint or a couple more print statements to see what is being added.

A long shot is if the “OccupiedBy” child is added and then the name is changed then moving the wait could mean that the new name isn’t being seen. Outputting it might let you see if that is happening.

print("child added", child, added)

Another would be if child isn’t a local variable. If it is global to the script then some other function changing it could confuse things.

That must be it!! Thanks, it should work now.

1 Like