Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I find out if whatever is touched is actually a body part?

Asked by
lilzy7 68
3 years ago
Edited 3 years ago

Lets say that I have a touched event:

local part = script.Parent

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    -- do whatever
    end
end)

This would work for things like body parts, but if I added an effect (lets say like a translucent part or sphere or something) and parented it to the character, then it would also think that the effect is also a body part. What is the best/most efficient way to stop this? My current solution is parenting the effect to the characters head or something, so it doesn't detect my effect as a body part.

0
If hit:IsA("BasePart") then (checks whether its a part) replace BasePart with MeshPart if you use custom characters with meshes Quicknoodle 2 — 3y
0
what if my character is made of baseparts and so are my effects? and is my solution good enough? lilzy7 68 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I'm not sure what you mean by effect, since particle emitters or lights cannot trigger the touched event. But if you don't want a part to be touched, you can turn off the CanTouch property for that part.

0
Oh i am talking about if the effect is a part, like for an example a sphere, but if there was a touch detecter then the sphere would act as a body part which I DONT want lilzy7 68 — 3y
0
I believe I've already answered that then. Do accept my answer if it worked. radiant_Light203 1166 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Maybe check the children inside of that instance. Like if the instance has children similar to a body part, you just claim it as a body part. Like this code example:

local Part = -- the part in the workspace which is going to be handling the event
Part.Touched:Connect(function(hit)
if hit:FindFirstChild("Anything similar to a body part inside of it (Motor3D, etc)") then
print("Print whatever inside of here")
end
end)

Sorry if it's too messy. But I think that will work for you.

0
Also this statement can be used with a and statement with the if statement to check if the particle emmiter is in there, or sparkles. Finty_james 269 — 3y

Answer this question