Multiple GetTouchingParts

I’m pretty new to scripting but i’ve gotten pretty far into a script im making

I can’t explain it very well but when using GetTouchingParts like this
for _,v in pairs(hum.Parent:GetTouchingParts()) do
hum.Parent is the player’s model part.

I’m making a script where touching anything damages you. Like knockback into a wall type stuff. Only issue is that i have no idea how to GetTouchingParts of multiple parts. Like getting the Left Arm right arm right leg left leg etc etc all at once. I can only get one part at a time.

Put this in a StarterCharacterScript (script)

repeat wait() until script.Parent.Humanoid
for i,v in pairs(script.Parent:GetChildren()) do
   if v:IsA("BasePart") then
      if v.Touched:Connect(function(hit)
       if hit and not hit.Parent:FindFirstChild("Humanoid") then
       --take damage

I don’t think you need :GetTouchingParts

I can’t put it in StarteCharacterScript but I can probably edit this a bit. Thank you. I’ll be back with results

Causes alot of unwanted issues. I want to stick with gettouchingparts

Can you specify your issue I don’t understand


This is the best i can explain it

When i hit a wall it only counts when i touch the humanoid root part. It doesent count the arms or legs or head. I need it to count those

repeat wait()
for i,v in pairs(<your part>:GetTouchingParts()) do
if v.Parent and v.Parent:FindFirstChild("Humanoid") then
--your condition

Maybe this is what you want

I think .Touch is better but I’ll stick to what you already have

This is exactly what i have above

Where it says Is where i need to put these parts
Right Arm
Right Leg
Left Arm
Left Leg

I edited it a little now any part from the player body counts

Could you put the edit here i don’t see it

Simply loop through all the body parts of the character, and attach a .Touched event to it.

As i said above i don’t want to use .touched, it would require rescripting a large portion of my code

Then just loop through all the body parts and check for all parts touching it, with a loop.

Yeah i have no idea how to do that lol

Simply, for loops. Do a quick search, if you don’t mind.


for _, BodyPart in ipairs(PlayerCharacter:GetDescendants()) do
   if BodyPart:IsA("BasePart") then
        -- Loop through 'BodyPart'.

Though, there is a little issue with that. It will yield the script, causing it to pretty much get stuck there/not execute any code below it, whatsoever. So I’d recommend using coroutine to prevent that.

I know how to do for loops but i dont how to loop through body parts

Thats what i came to ask today

How do i loop through BodyPart

Oh, my bad, I meant to say, you then address a variable with the parts touching ‘BodyPart’, loop through them, and do your stuff.

Alright i’ll try that. Ive done that a second ago and it was having some issues