How do you make a sword click to do damage?

How do you make a sword click to do damage?:

  1. I want to achieve click to damage

  2. I have tried using String Value to detect if CanDamage is True or False

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is the script:
Blade.Touched:Connect(function(hit)
local enemyH = hit.Parent:FindFirstChild(“Humanoid”)
if enemyH then
if CanDamage.Value == “True” then
if not db then
db = true
enemyH:TakeDamage(5)
wait(0.6)
db = false
end
end
end
end)

Thanks for read and the help!

You can use boolValues instead of stringValue.

I have no idea what ‘db’ is. Dont overthink it, you got the right path, you just need to check if the bool variable your using is true. If so, make the bool value to false and damage the humanoid. Afterwards, add task.Wait(cooldownLength) and once the wait time finishes, make the variable true again.

Cant code it because im on mobile :disappointed:

Uh is the can damage a bool value?!

db is debounce Thanks for the help!

Yes can damage is the bool value

Blade.Touched:Connect(function(hit)
	local enemyH = hit.Parent:FindFirstChildOfClass("Humanoid")
	if enemyH then
		if CanDamage.Value == true then
			if db ~= true then
				db = true
				enemyH:TakeDamage(5)
				delay(0.6,function() -- I changed it because it might yeild the whole script
					db = false
				end)
			end
		end
	end
end)

That might work for you

did it work?

check how the debounce works inside the if statement

what do you mean?

It did not work, But thanks for trying

did it have any errors at all

My problem is every time the blade hits it damages the humanoid when i didn’t click.

ohhhh i get it now

do you have a click event?

yes tool:Activated:Connect(function)
–Damage
end)

could you give the actual script?

local tool = script.Parent

repeat wait() until game.Players:GetPlayerFromCharacter(tool.Parent)
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
local db = false
local hum = player.Character:FindFirstChild(“Humanoid”)

local count = 0
local db = false
local CanDamage = script.Damage
local Blade = tool.OldSword.OldBlade

local hold = hum:LoadAnimation(script.Hold)
local A1 = hum:LoadAnimation(script.A1)
local A2 = hum:LoadAnimation(script.A2)
local A3 = hum:LoadAnimation(script.A3)

tool.Equipped:Connect(function()
hold:Play()
end)

tool.Unequipped:Connect(function()
hold:Stop()
end)

tool.Activated:Connect(function()
if not db then
db = true
count = count + 1
if count == 1 then
A1:Play()
end
if count == 2 then
A2:Play()
end
if count == 3 then
A3:Play()
count = 0
end

	CanDamage.Value = true
	
	Blade.Touched:Connect(function(hit)
		local enemyH = hit.Parent:FindFirstChild("Humanoid")
		if enemyH then
			if CanDamage.Value == true then
				if not db then
					db = true
					enemyH:TakeDamage(5)
					wait(0.6)
					db = false
				end
			end
		end
	end)

	wait(0.6)
	CanDamage.Value = false
	db = false
end

end)

1 Like
local tool = script.Parent
repeat wait() until game.Players:GetPlayerFromCharacter(tool.Parent)
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
local db = false
local hum = player.Character:FindFirstChild("Humanoid")

local count = 0
local db = false
local db2 = false
local CanDamage = script.Damage
local Blade = tool.OldSword.OldBlade

local hold = hum:LoadAnimation(script.Hold)
local A1 = hum:LoadAnimation(script.A1)
local A2 = hum:LoadAnimation(script.A2)
local A3 = hum:LoadAnimation(script.A3)

tool.Equipped:Connect(function()
	hold:Play()
end)

tool.Unequipped:Connect(function()
	hold:Stop()
end)

tool.Activated:Connect(function()
	if not db then
		db = true
		count = count + 1
		if count == 1 then
			A1:Play()
		end
		if count == 2 then
			A2:Play()
		end
		if count == 3 then
			A3:Play()
			count = 0
		end

		CanDamage.Value = true

		Blade.Touched:Connect(function(hit)
			local enemyH = hit.Parent:FindFirstChild("Humanoid")
			if enemyH then
				if CanDamage.Value == true then
					if not db2 then
						db2 = true
						enemyH:TakeDamage(5)
						wait(0.6)
						db2 = false
					end
				end
			end
		end)
		delay(.65,function()
			CanDamage.Value = false
		end)
		db = false
	end
end)



Maybe this will work?

6 Likes

Yes finally its works thank you so much!!

1 Like