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
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