Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you detect when any part with a specific name within a folder is hit?

I'm trying to detect when any part named "SignalSensor" within the folder is hit and then change a value that is kept inside the parent of the SignalSensor part.

I thought maybe adding the sensors to a table but I've hit a dead end with what to do next. Thanks

sensors = {}
local desc = script.Parent:GetDescendants()

for index, desc in pairs(desc) do
	if desc.Name == "SignalSensor" then
		table.insert(sensors, desc)
		warn("Signal Added To Table")
		print(sensors)
	end
end

The goal is to detect which sensor is hit and then do something similar to this

hitSensor.Parent.SignalValues.TrainInBlock.Value = true

3 comments

0

What do you mean by "Hit"? Like touched? If so, just use the .Touched event

0

Yes I do mean touched. How would I use Touched with multiple parts? Would I use the table name or something?

0

doesn't matter anymore; i've found a way to do it locally instead

1 answer

I'm assuming you already know the parts' folder, so here we go.

local folder = workspace.SignalSensors --change this to the **Parent** of the sensors

--.Touched function for the Sensor
touched(sensor)
	sensor.Touched:Connect(function(hit)
		--change the value in here.
	end)
end

--Indexing through the folder, finding SignalSensors and assigning them the function.
for i,v in next, folder:GetChildren() do
	if v.Name == "SignalSensor" then
		touched(v)
	end
end

1 comment

0

the problem is that within the folder there is groups with other parts - the sensors are grouped to the specific signal that they are detecting for

This discussion is preserved as it was. New answers, comments, and votes are closed.