3

# How can I listen for when multiple bricks touch something?

TomsGames 225
9 years ago

This is the current layout of my script:

http://gyazo.com/30d6b94f738d29ffd6e3ee351ac9ddff

The script does not function, as a question I posted before somebody said local and non-local scripts do not function inside the camera. Right.

So I have multiple 'hitsensors' in this car (which is inside currentcamera), how can I listen to all of them at the same time and wait until one is touched?

0
9 years ago

First of all, since you are dealing with local parts, this has to be done inside of a local script to work.

What you are literally asking for is how to connect multiple events to the same function, which as is simple as it sounds:

local deb = false

function HitDetected(partHit)
if not deb then deb = true else return end
print("Object hit from " .. partHit:GetFullName())
wait(5)
deb = false
end

for _, v in ipairs(Parts) do
if v.Name == "HitSensors" then
v.Touched:connect(HitDetected)
end
end

0
You need to note that you won't be able to find out which part was hit though. Only the part that touched it. Bubby4j 231 — 9y
0
Bubby4j 231
9 years ago

Place this script within a model containing all the parts you want to connect to. With this script, you're able to get BOTH the part that was touched, and the part that touched it.

function partTouched(touchee, toucher)
--touchee is the part that was touched
--toucher is the part that touched the touchee

end

local parts = script.Parent:GetChildren()
for i = 1, #parts do
if parts[i]:IsA("BasePart") then
parts[i].Touched:connect(function(toucher)
partTouched(parts[i],toucher)
end)
end
end