Damage script not working correctly

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.

Can we see the “char” variable and how it is defined?

1 Like

Edit: Nevermind. You do use the “h” variable, I just misread.

1 Like

The char variable is simply plr.Character
and I do use the t,h variables

Can you try something like

1 Like

Sure thing lemme try that real quick ill let you know what comes of it.

same issue occurs when I change char to plr.Character

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.

@lifacy @stayinjured

I just added plr.Character to the hittable and it seems to work fine now.

1 Like