Okay so I have this combat system and it seems to work fine except for one part.
for i,v in pairs(GetTouchingParts(char[wponName][weapon].hitbox)) do
local db = false
if v.Parent:FindFirstChild("Humanoid") then
for t,h in pairs(hittable) do
if v:IsDescendantOf(char) then
db = true
elseif v.Parent == h then
db = true
if db == false then
-- damage is dealt.
obviously thats not the full script but thats the part im stuck on. (where the problem occurs)
INTENDED TO DO: When you swing a weapon it gets all the touching parts and returns them. It cycles through them and since theres a chance it can grab two of your body parts the loop can run and damage the victim twice. To prevent this the loop grabs the players character and puts it into a table after its damaged once. If anything is in that table then damage wont register. It also checks if the parts belong to the person doing the attack by checking if its a descendant of the character.
WHAT IT DOES: It can hit the player doing the attack for some reason despite my measure to stop it. Everything else seems to work fine except the fact that I can hit myself.
after messing around with prints it seems that db = false everytime it damages myself.
I think the issue is that the check fails for some reason. I added a print to check if it considers myself a descendant of char and it does sometimes but other times it doesn’t for some reason and when I print the part its checking its my humanoidrootpart.