Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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
0
What do you mean by "Hit"? Like touched? If so, just use the .Touched event qChaos 86 — 4y
0
Yes I do mean touched. How would I use Touched with multiple parts? Would I use the table name or something? kieranhendy 28 — 4y
0
doesn't matter anymore; i've found a way to do it locally instead kieranhendy 28 — 4y

1 answer

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
4 years ago
Edited 4 years ago

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
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 kieranhendy 28 — 4y
Ad

Answer this question