Touched function doesnt work

So this is my code and what I am trying to do is that when a diffrent player then the player that activated touches the hitbox this function triggers but it isnt working and there are also no errors
maybe you can still help me.

	local NewHitbox = Hitbox:Clone()
		NewHitbox.Parent = game.Workspace
		NewHitbox.CFrame = tool.Parent.HumanoidRootPart.CFrame*CFrame.new(0,0,-5)
		NewHitbox.Touched:Connect(function(hit)
			if hitdebounce == false and hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= tool.Parent then
				hitdebounce = true
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
				task.wait(1)
				hitdebounce = false
			end
		end)

Thanks in advance.

Why are you doing this? This may be the reason your code isnt working

Hit.Parent = Character
Tool.Parent = Character

that I don’t hit myself it is working normaly and if I remove it its just the same expect I can hit myself

That’s not how that works,

Lemme break it down,

Your if statement is saying:

If:

  • Your debounce is false
  • if it Finds a Humanoid
  • if the Tools Parent isn’t Hit.Parent

The First two Ifs are returning true, the third is returning false because you are telling it that hit.Parent isnt Tool.Parent, and their Parents are your Character.

Since the third is false, the code will not run

Cairo, that condition is just fine, what are you talking about??

When the Event detects the part that’s hitting it, the if statement is looking for a Humanoid within the said part’s parent, If the Player is holding the Tool, the Tool is inside the Character, thus Tool.Parent is your Character,

hit.Parent:FindFirstChild("Humanoid") is looking for the parts Parent that Contains a Humanoid, The Players Character as the parts parent is the Character, and its looking for a Humanoid

So when the part detects the Collusion, inside the if statement its looking for if Hit.Parent is not equal to Tool.Parent, Since they are both your Character, it will return false

That is literally the exact point??
Tool.Parent = YOUR character
Hit.Parent = ANY character including YOURS
If Hit.Parent is equal to YOUR character, then you are hitting yourself. It will return false and thus you WONT damage yourself.

1 Like

Anyways, I just want to know a few other things. It doesn’t seem like there’s anything wrong with the actual code.
Is this in a local script?
What do the hitbox properties look like?
Are you attacking a dummy, or an actual player?

its a server script inside of a tool,
its anchored, can be touched, can’t be collided with
and I am attacking a dummy

Ok, may you show me the children of the dummy in the explorer tab?

218c2110e8cc1a95a7c0c0f8fd83624b

And the issue is that it doesn’t damage the dummy whatsoever, right?

I mean yea basicly that it does nothing with it.

This is how it looks right now:


(ignore the animation and highlight they are not important)

Oh. The issue is that .Touched doesn’t work on things that aren’t moving.

1 Like

omg thx lol it really does I unachored the humanoidrootpart and now it works tysm.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.