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.
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
end)
end
end
repeat wait()
for i,v in pairs(<your part>:GetTouchingParts()) do
if v.Parent and v.Parent:FindFirstChild("Humanoid") then
print("Touch")
end
end
until
--your condition
Maybe this is what you want
I think .Touch is better but I’ll stick to what you already have
for _, BodyPart in ipairs(PlayerCharacter:GetDescendants()) do
if BodyPart:IsA("BasePart") then
-- Loop through 'BodyPart'.
end
end
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.