How i can make if weapon make humanoid damage in a time, and it will destroy damaging?

Hi i making fighting game, but there is a problem when click on weapon and animation end then i walked to dummy and it still take damage can anyone fix this here my part of code that i think it problem

local canDamage = false
local canSwing = true
	local function onTouch(otherPart)
		
		local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
		
		if not humanoid then
			return
		end
		
		if humanoid.Parent ~= tool.Parent and canDamage then
		humanoid:TakeDamage(10)
		canDamage = false
		humanoid.WalkSpeed = 0.5
		wait(1)
		humanoid.WalkSpeed = 16
		else
			return
		end
		
		canDamage = false
	end

Where you have the swing (can’t show because you don’t have it included), at the end of the swing change canDamage to false.

1 Like
	local function slash()
	local str = Instance.new("StringValue")
	local hum = script.Parent.Parent:WaitForChild("Humanoid")
	local humleft = hum:LoadAnimation(script.Left)
	local humright = hum:LoadAnimation(script.Right)
	local hummiddle = hum:LoadAnimation(script.Middle)
	if script.Parent.Slash.Value == 1 and canSwing then
		script.Parent.Slash.Value = script.Parent.Slash.Value + 1
		str.Name = "toolanim"
		str.Value = "Slash"
		canDamage = true
		humleft:Play()
		canSwing = false
		wait(0.3)
		canSwing = true
	elseif script.Parent.Slash.Value == 2 and canSwing then
		script.Parent.Slash.Value = script.Parent.Slash.Value + 1
		str.Name = "toolanim"
		str.Value = "Slash"
		canDamage = true
		humright:Play()
		canSwing = false
		wait(0.3)
		canSwing = true
	elseif script.Parent.Slash.Value == 3 and canSwing then
		script.Parent.Slash.Value = script.Parent.Slash.Value + 1
		str.Name = "toolanim"
		str.Value = "Slash"
		canDamage = true
		hummiddle:Play()
		canSwing = false
		wait(0.3)
		canSwing = true
	end
	if script.Parent.Slash.Value >= 4 then
		script.Parent.Slash.Value = 1
	end
	
	
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

this is function slash script

There are multiple of these lines in each, add a canDamage = false after or before each canSwing = true

alright it worked thank aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

You pretty much already had it, but here:

local canDamage = true
local canSwing = true

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if not humanoid then
		return
	end
	if humanoid.Parent ~= tool.Parent and canDamage then
		humanoid:TakeDamage(10)
		canDamage = false
		humanoid.WalkSpeed = 0.5
		task.wait(1)
		humanoid.WalkSpeed = 16
	else
		return
	end
	task.wait(1)
	canDamage = true
end
1 Like