Hitbox.Touched keeps repeating

Hey so basically i made a hitbox right that if it hits u, you take 2 damage and u go flying and it prints hit whenever it gets touched. The problem is that im tryna make it touch only once because every time i fire it, it repeatedly touches the target and for the printed hit, it says it prints more then 100 times. How do I fix this?

Hitbox.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Name == "Stand" then
			if not hit:IsDescendantOf(Character) then
				print("Hit")
				local enemyHum = hit.Parent:FindFirstChild("Humanoid")
				local enemyrp = hit.Parent:FindFirstChild("HumanoidRootPart")
				local enemyChar = enemyHum.Parent
				local enemy = game.Players:GetPlayerFromCharacter(enemyChar)
				
				HitSFX.Parent = StandRP
				HitSFX:Play()
				
				local BV = Instance.new("BodyVelocity", enemyrp)
				BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				BV.P = 10000
				BV.Velocity = HumRP.CFrame.LookVector * 10 + Vector3.new(0,10,0)
				game.Debris:AddItem(BV,1)
					
				HitSFX.Ended:Connect(function()
					StandRP.HitSFX:Remove()
				end)
				enemyHum:TakeDamage(2)
				
				TS:Create(StandWeld,Info,{C1 = CFrame.new(2,-1,-2)}):Play()
			end	
		end		
	end)

Add a debounce. This is because of physics and animations and whatnot. Im no expert in this topic.

2 Likes

What is debounce gonna do? Where do I put it? And if your not an expert then why did u comment?

You didn’t have to be rude about that. Just because they’re not an expert doesn’t mean they don’t know what they’re talking about. Yes, he was correct. You need a debounce to stop the touched event from repeating until it is done with what it needed to do.

5 Likes

I’m quite literally here to help people. If the people I am trying to help are rude, I am less inclined to help them. I can handle criticism, but you are literally insulting and being rude to the people trying to HELP you. Just because you need help doesn’t mean we need to help you.

1 Like

As the other two said, you should just use a debounce.
If you want each player to have their own debounce create a table and store their id in there and remove it when you want them to be able to touch it again.

It’s something like this:

local debounce = false

Obj.Touched:Connect(function()
	if (debounce) then
		return
	end
	
	debounce = true
	
	task.wait(1)
	
	debounce = false
end)

First of all, everything your saying is the opposite of whats going on at the moment. And also what the heck are you talking about im not being rude i was asking a question in proper manner and you assumed i was being rude. Not only that but you had the audacity to include yourself as someone that is trying to help me. No one asked for your help nor for your opinion. OnceCrowned doesnt have a problem with me yet you do just because I asked a question they seemed rude to you.

What exactly is the opposite here?

this is quite rude in itself. Asking someone why they are helping you just because they aren’t an expert. I don’t know your stance, but this is rude.

I was trying to help, though? I had told you that the person was correct, and that a debounce was the answer.

You literally asked for help by making a post.

That’s because most people find it too much of a hassle to deal with. He simply restated the answer, provided you with an example of it, and left it there.