How do I make my sword only hit once

  1. What do you want to achieve? Keep it simple and clear!
    How do I make my sword only hit once and deal 22 damage to the npc instead of instant kill them

  2. What is the issue? Include screenshots / videos if possible!
    The sword just instant kill the dummy

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Adding debouce but doesn’t seems to work

local tool = script.Parent
local deb = false
local combo = 1
local Particle = script.Parent.Handle.Attachment1.ParticleEmitter
local HiEffect = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local trail = script.Parent.Handle.Trail

tool.Activated:Connect(function()
	if deb == false then
		deb = true
		local char = script.Parent.Parent
		local humrp = char:WaitForChild("HumanoidRootPart")
		local hum = char:WaitForChild("Humanoid")
		
		trail.Enabled = true
		Particle.Enabled = true
		
		if combo == 1 then
			local Anim = script.Swing1
			local Track = hum:LoadAnimation(Anim)
			Track:Play()
			combo = 2
		else
			local Anim = script.Swing2
			local Track = hum:LoadAnimation(Anim)
			Track:Play()
			combo = 1
		end
		
		local sound = script.M1
		sound:Play()

		
		local bv = Instance.new("BodyVelocity")
		bv.MaxForce = Vector3.new(10000,10000,10000)
		bv.Velocity = (humrp.CFrame.lookVector * 15)
		bv.Parent = humrp
		hum.WalkSpeed = 0
		local canhit = true
		script.Parent.Handle.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent ~= char then
					if canhit == true then
						local thumrp = hit.Parent.HumanoidRootPart
						
						local sound = script.M1hit
						sound:Play()
						
						HiEffect.Gore1(thumrp)

						local bv = Instance.new("BodyVelocity")
						bv.MaxForce = Vector3.new(11000,11000,11000)
						bv.Velocity = (humrp.CFrame.lookVector * 50)
						bv.Parent = thumrp
						hit.Parent.Humanoid:TakeDamage(22)
						wait(0.1)
						bv:Destroy()
						canhit = false
					end
				end
			end
		end)
		wait(0.2)
		bv:Destroy()

		wait(0.1)
		hum.WalkSpeed = 16
		trail.Enabled = false
		Particle.Enabled = false
		canhit = true
		deb = false
	end
end)

The code is in a normal script in a tool

The problem :

also if you know how to make it so that the sword only hit 1 dummy per swing, please tell how to do it too, I would be very appreciated

Add a debounce when the sword causes any damage to an opposing player. Make sure further damage can’t be dealt by that sword until the debounce has expired, I know you mentioned you tried using one but if you used it correctly then it would work.

1 Like

I tried to change the canHit to other lines but now the sword only hit once and then it won’t hit at all

local tool = script.Parent
local debounce = false
local combo = 1
local Particle = script.Parent.Handle.Attachment1.ParticleEmitter
local HiEffect = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local trail = script.Parent.Handle.Trail

tool.Activated:Connect(function()
	local char = script.Parent.Parent
	local humrp = char:WaitForChild("HumanoidRootPart")
	local hum = char:WaitForChild("Humanoid")

	trail.Enabled = true
	Particle.Enabled = true

	if combo == 1 then
		local Anim = script.Swing1
		local Track = hum:LoadAnimation(Anim)
		Track:Play()
		combo = 2
	else
		local Anim = script.Swing2
		local Track = hum:LoadAnimation(Anim)
		Track:Play()
		combo = 1
	end

	local sound = script.M1
	sound:Play()


	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(10000,10000,10000)
	bv.Velocity = (humrp.CFrame.lookVector * 15)
	bv.Parent = humrp
	hum.WalkSpeed = 0
	script.Parent.Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent ~= char then
				if debounce then
					return
				end
				debounce = true
				local thumrp = hit.Parent.HumanoidRootPart
				local sound = script.M1hit
				sound:Play()

				HiEffect.Gore1(thumrp)

				local bv = Instance.new("BodyVelocity")
				bv.MaxForce = Vector3.new(11000,11000,11000)
				bv.Velocity = (humrp.CFrame.lookVector * 50)
				bv.Parent = thumrp
				hit.Parent.Humanoid:TakeDamage(25)
				task.wait(0.2)
				bv:Destroy()
				debounce = false
			end
		end
	end)
	task.wait(0.2)
	bv:Destroy()
	hum.WalkSpeed = 16
	trail.Enabled = false
	Particle.Enabled = false
end)

I’ve added one which lasts for 0.2 seconds, feel free to increase that delay if necessary.

hit.Parent.Humanoid:TakeDamage(25)
task.wait(0.2)

Just change the “0.2” here.

I got rid of canhit entirely I believe.

so, all you need to do is just put script.Parent.Handle.Touched
outside of tool.Activated
also put local char,humrp,hum = nil,nil,nil outside
:sweat_smile:

You can make a Humanoid variable which is equals to nil in the activated function when you click with the tool.

Then, when the sword hits a humanoid
it checks for Variable Humanoid.

If the variable == nil, then hurt the humanoid and set the Variable Humanoid to the damaged humanoid.

Otherwise, do not hurt the humanoid.

just use debounce bruh

local db = false
  if not db then
  db = true
  -- smthing
  wait(1)
  db = false
end
local tool = script.Parent
local deb = false
local combo = 1
local Particle = script.Parent.Handle.Attachment1.ParticleEmitter
local HiEffect = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local trail = script.Parent.Handle.Trail

tool.Activated:Connect(function()
	if deb == false then
		deb = true
		local char = script.Parent.Parent
		local humrp = char:WaitForChild("HumanoidRootPart")
		local hum = char:WaitForChild("Humanoid")
		
		trail.Enabled = true
		Particle.Enabled = true
		
		if combo == 1 then
			local Anim = script.Swing1
			local Track = hum:LoadAnimation(Anim)
			Track:Play()
			combo = 2
		else
			local Anim = script.Swing2
			local Track = hum:LoadAnimation(Anim)
			Track:Play()
			combo = 1

		end
		
		local sound = script.M1
		sound:Play()

		
		local bv = Instance.new("BodyVelocity")
		bv.MaxForce = Vector3.new(10000,10000,10000)
		bv.Velocity = (humrp.CFrame.lookVector * 15)
		bv.Parent = humrp
		hum.WalkSpeed = 0
		local canhit = true

                local HittedHum = nil


		script.Parent.Handle.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent ~= char then
					if canhit == true then
						if HittedHum == nil then
                                                    HittedHum = hit.Parent.Humanoid
                                                    local thumrp = hit.Parent.HumanoidRootPart
						
						    local sound = script.M1hit
						    sound:Play()
						
						    HiEffect.Gore1(thumrp)

						    local bv = Instance.new("BodyVelocity")
						    bv.MaxForce = Vector3.new(11000,11000,11000)
						    bv.Velocity = (humrp.CFrame.lookVector * 50)
						    bv.Parent = thumrp
						    hit.Parent.Humanoid:TakeDamage(22)
						    wait(0.1)
						    bv:Destroy()
						    canhit = false
                                                end
					end
				end
			end
		end)
		wait(0.2)
		bv:Destroy()

		wait(0.1)
		hum.WalkSpeed = 16
		trail.Enabled = false
		Particle.Enabled = false
		canhit = true
		deb = false
	end
end)

I tried to make minimum change to the code.
Take note of the HittedHum section

All these time i was replying to the wrong person lol
@Fizzavocadoo

1 Like

just count the number of dummies and if there are more than 1 just damage the first one…example

local dummies = 0
script.Parent.Touched:Connect(function(hit)
  if dummies ~= 1 then
    if hit.Parent.Name == "Dummy" then
      dummies = 1
    end
  end
end)

my code was a example but alright

1 Like

Anything which isn’t dealing damage doesn’t need a debounce, I’ve already fixed the debounce for damage so it should work.

and i wrote this for dummy cap i think it would work cuz didint tested

Your sword is insta killing because your Touch Event is firing without limit.

You need to add the debounce to the touch, not the Activate Event.

Also, this has been mentioned, you need to move your touch Event outside of Activate, because every time you click, you create a new touch, which will multiply your damage every time.

1 Like