How do I make the Handle not deals damage anymore?

I made a sword-skill script. Where when you press a keybind, it will runs a skill. But theres a trouble.

So I want it that the skill I made wont deal damage when the skill already runs. The problem is when the skill animation is over, the tool handle still deals damage. I want it so that it doesnt deal damage when you don’t use the skill anymore.

I looked for similar topic but couldn’t find the perfect solution. I was also just learnt some scripts like this.

This is the script that I wrote.

Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
			local VCharacter = game.Workspace:FindFirstChild(plr.Name)
	        local vPlayer = game.Players:GetPlayerFromCharacter(VCharacter)
			tagHumanoid(hit.Parent:FindFirstChild("Humanoid"),vPlayer)
			hit.Parent.Humanoid:TakeDamage(30)
			wait(0.05)
			untagHumanoid(hit.Parent:FindFirstChild("Humanoid"))
		end
	end)

At the end, all I just want is to disable this function but I don’t know how.

you can make the connection a variable and disconnect it when it hits something

local Connection = nil
Connection = Handle.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
        local VCharacter = game.Workspace:FindFirstChild(plr.Name)
        local vPlayer = game.Players:GetPlayerFromCharacter(VCharacter)
        tagHumanoid(hit.Parent:FindFirstChild("Humanoid"),vPlayer)
        hit.Parent.Humanoid:TakeDamage(30)
        Connection:Disconnect()
        Connection = nil
        wait(0.05)
        untagHumanoid(hit.Parent:FindFirstChild("Humanoid"))
    end
end)

Thanks so much sir! Its really working. You are really a life savior!

1 Like