Need Help With My "Block Ownership Signalling" System involving .Touched and .TouchEnded

  1. What do you want to achieve? I want to make this system work in the following way. 1) A train enters a block zone. 2) The script recognizes that the train is in a block zone, and stores that in an ObjectValue. 3) I can use the ObjectValue with Train Arrival Signs and Signal Lights.

  2. What is the issue? My code is using the “Wheel” parts of my train, and my code kind of works, but it seems that when a train is in a signalling block, the ownership will switch on and off crazy fast.

Here’s my code:

local system = script.Parent
local blocks = system.Blocks
local lights = system.Signals

local touching = false

for i, v in pairs(blocks:GetDescendants()) do
	print (i, v)
	if v.Name == "blockPart" then
			if touching == false then
				if v.Parent.Value.Value == nil then
					print("touched function begins")
					if hit.Name == "Wheel" then
						v.Parent.Value.Value = hit.Parent.Parent.Parent.Parent
						print(tostring(v.Parent).." is now occupied.")
						touching = true
			print("TOUCH ENDED!")
			if touching == true then
				if hit.Name == "Wheel" then
					if #workspace:GetPartsInPart(v) == 0 then
						v.Parent.Value.Value = nil
						print(tostring(v.Parent).." is now unoccupied.")
						touching = false
  1. What solutions have you tried so far? I looked on the DevForum and DevHub as well as did lots of experimenting with different systems and functions, but nothing worked.

This system is based off of the NYC Subway’s Block signaling system.

For more information about NYC Subway Block signaling:


This is going to be a difficult and inconsistent way to do this. I would recommend a different system that uses invisible parts to define each block then checks a list of trains for which ones are in each block.

1 Like

that’s what im doing, except there are multiple parts that check the train in the block; this is because the track curves.

.Touched and .TouchEnded are fairly inconsistent in their firing. There is a system that can detect if parts are in a certain area that I think would be better suited for this:
See Methods Section:

1 Like

any idea how specifically i could implement this?
thx in advance

Here is an example of how you could do it. The red blocks are train locations, the gray parts would be your invisible markers for blocks. These change color for caution and danger respectively if you move the trains around. Right now you have to manually specify which blocks are adjacent to eachother (see the script) but you could come up with a way to automate this part if you have lots of tracks.

blocksections.rbxl (49.7 KB)

1 Like

This looks like a great system and thanks for making this just for an explanation. However, I really do not understand how the script works, and if I want to manipulate it so I can do other things with the blocks (like making Next Train to Arrive indicators,) I need to know how this works. Can you please explain how this script functions?

Don’t worry about it I also needed it for someone else. Each Block in the Tracks model defines an area which is one block section of tracks. The calls to AddLink specify which blocks are connected to eachother, this is the manual part.

CurrentBlock must return which block (a Model in the workspace) the given position maps to. It just raycasts down until it hits a part. This part is replacable depending on how you want your marker pieces to be shaped.

SetHighlightBlock just colors a model red, yellow, or gray, depending on ‘level’ being 2, 1, or 0 respectively. You could change this to toggle your lights and signs, since you have access to both the danger level and which train is in the block.

Calling UpdateBlock will check which blocks should be at danger or caution. It also calls SetHighlightBlock to visualize this.

There are some table shenanigans used to search the network for connected blocks, you don’t actually need to worry about how this works if you only need the results. There is no pathfinding involed, that’s a separate task, but it does use the same information about how blocks are connected.

Your pathfinder could use the total length left in the train’s path, and the trains speed, to update Next Train signs.

1 Like

thank you so much. this is gonna help me out a TON with my project. happy 4th.

1 Like

shoot. I forgot to ask… what are those green parts?

1 Like

I just put those there to imagine where the signals would be.

1 Like

oh thx. also I have figured out exactly how to use this system to work in my game and I will make sure to credit you. you’re a life saver :happy3:

1 Like

sorry to continue this i actually noticed an issue. I organized my things exactly how your setup was. possible issue: train is a model and so it is not noticed; OR, signal blocks are a folder so they aren’t noticed. any clue? edit: the train is also fairly long, and the position setting may be effected during curves or may cause an issue allowing some of the train to be in a caution block, meaning a collission could occur

You can make a specific part on the train be the “sensor” for blocks. Then you need to change the CurrentBlock function to get that instead of just the positions of every part in the Trains folder.

1 Like

how can i solve this issue then

Probably the easiest is to just put a sensor on each car.

1 Like

ok. thank you very much but how would i reflect that in the script? also thank you for all the help once again

sorry for mentioning you again, could you please check my latest reply before this one?

You would need to make UpdateBlocks check each sensor in each car instead of just the ones in the Trains model.

I did so. Now the script just keeps printing the error “Train not on tracks” even when the sensors are above the tracks