Hi, I’m trying to make a bodypart health system where if I were to strike my sword (tool) onto a person, the part where it hits will get damage. (R15 character)
I’m quite new to scripting so bear with me.
if TOUCHED.Name == "RightHand" or "RightUpperArm" or "RightLowerArm" then
local limbhealth = TOUCHED.Parent:WaitForChild("RightArm")
limbhealth.Value = limbhealth.Value - 1
print("rightlimb")
print(TOUCHED.Name.. "right")
else
if TOUCHED.Name == "LeftHand" or "LeftUpperArm" or "LeftLowerArm" then
local limbhealth = TOUCHED.Parent:WaitForChild("LeftArm")
limbhealth.Value = limbhealth.Value - 1
print("leftlimb")
print(TOUCHED.Name.. "left")
else
HUM:TakeDamage(1)
print("dmgtaken")
print(TOUCHED.Name)
end
end
The issue is that if the hit is another bodypart, it would still register as the first “if” line. So if I were to hit the left limb, it’d still take damage on the right limb’s IntValue.
The problem with this script is in the first line, the if conditional. Basically, you’re saying that if the touched part is Right hand OR the string RightUpperArm etc. exists, which will always be true. If you want an easy solution, here:
local Parts = {
"RightHand",
"RightUpperArm"
}
if table.find(Parts, TOUCHED.Name) then
-- Code
end
OK, I’ve just changed my script into using Raycasting for my script but it works similar to Touched because why not but the process is similar. Is this what you’re trying to get me to do? Here’s the script but it doesn’t register the ‘if’ sentence and goes straight to the else line. (sorry table isn’t a very strong topic for me)
newHitbox.OnHit:Connect(function(hit, humanoid)
print(hit)
local Parts = {
"LeftHand",
"LeftUpperArm",
"LeftLowerArm"
}
if table.find(Parts, hit) then
humanoid.Parent.LeftArm.Value = humanoid.Parent.LeftArm.Value - 10
print("left")
else
humanoid:TakeDamage(5)
end
end)