Is there a way to detect the part in a model that has touched?

So there are three pads that are in a model, and a ball this is going to fall at the top.
How can I detect which one of the pads has been touched without having to put a script in all of the pads?

I know this is kinda confusing but I need it to work for all three pads, or more (maybe even like 100 parts)

Best idea I’ve got so far is putting a script in each part, but that might be laggy.

You can instead put a touch script on the ball to detect which part is touched.

Well, I need it to be in the model because the parts are going to be on a vehicle and I don’t want to put a script in every part in the map.

I have an Idea here, in this situation, what I would do is make three functions, then activate them when a specific part is touched, one sec I’ll make a script

function part1touched()

print(“Part1Touched”)

end

function part2touched()

print(“Part2Touched”)

end

function part3touched()

print(“Part2Touched”)

end

script.Parent.Parent.Part1.Touched:Connect(part1touched())

script.Parent.Parent.Part2.Touched:Connect(part2touched())

script.Parent.Parent.Part3.Touched:Connect(part3touched())

is this what you were looking for?

Good idea. Rename the parts with a different name like: Part1, Part2, Part3

You can put the touch script into the model instead of every part in the map.

Well, I need it to work for possibly 100 parts or more.

Instead of renaming every part manually just iterate through all the parts in your model and attach connections to them within a loop

local model = script.Parent

for i, Part in pairs(model:GetChildren()) do
   Part.Touched:Connect(function()
      print("The ball touched ".. Part.Name)
   end)
end
5 Likes

So I basically need a script in a model to get any part within the model that has been touched.

This here, use this. However make sure that it’s a BasePart before doing Part.Touched because if you have anything else in the model that isn’t a part, it will error.

for _, part in pairs(script.Parent:GetChildren()) do
	if part:IsA("BasePart") then
		part.Touched:Connect(function()
			print("The ball touched "..part.Name)
		end)
	end
end

1 Like

Try the script i posted, it will work with as much parts your model has

Wow, thanks I didn’t know it was that simple