.Touched event in model

Hello, I have a question regarding .Touched event in models. Here I have this hierarchy:
https://gyazo.com/e054324e7b5bbc30aa8f29c23041b323
and here is the code.

for i,v in pairs(workspace:WaitForChild('CTF'):GetDescendants()) do
	if v:IsA('BasePart') and v.Name == 'Area1' then
		v.Touched:Connect(Capture)
		PartThatGotTouched = v
		print(v)
	end
	
end

What I want it to do is give me the part INSIDE the model that was touched.
What it does right now is just confirm that I have touched the model, but only gives me the last part that has been run through the for loop.
My question:
Is it possible to do so, and if not, are there any other alternatives?

1 Like

I’m thinking you should connect and send the v variable into the function and then print it there.

for i,v in pairs(workspace:WaitForChild('CTF'):GetDescendants()) do
	if v:IsA('BasePart') and v.Name == 'Area1' then
		v.Touched:Connect(Capture, v) -- sending v as an argument
	end
	
end

And then in your Capture function, print it there:

function Capture(PartThatGotTouched)
    print(PartThatGotTouched)
end

This should print the proper part.

Also, just a heads up, you can download gifs and images from Gyazo and upload them here :stuck_out_tongue:

2 Likes

@7z99
When I do this, it gives me the part that touched the Area1, not which Area1 it is.
Here’s a video:

So what I want is the part that is touched should be printed, instead of CTwo or the Plr Limbs, which gets printed every time I touch a part inside the CTF model.

I’m a bit confused, but if I understood your question correctly, maybe something like this?

for i,v in pairs(workspace:WaitForChild('CTF'):GetDescendants()) do
	if v:IsA('BasePart') and v.Name == 'Area1' then
		v.Touched:Connect(function(hit)
                      Capture(v) --//Pass in the part itself
                 end)
	end
	
end