Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make my tool deal a specific amount of damage ONLY when its animation plays?

To clarify, I want to know how I can STOP it from dealing damage when the tool is NOT moving, and how it CAN deal damage ONLY when the tool is moving. I don't want to to be like the classic roblox sword.

I have this script here, I need to know what I can add to it that will allow the tool to deal damage ONLY when its animation plays..

Script:

local Tool = script.Parent
local Animation = Tool.Animation
local activeCooldown = false
local cooldownTime = 3 

Tool.Activated:Connect(function()
	if (activeCooldown) then
		return 
	else
		activeCooldown = true 

		local Character = Tool.Parent
		local Humanoid = Character.Humanoid

		local AnimationTrack = Humanoid:LoadAnimation(Animation)
		cooldownTime = AnimationTrack.Length

		AnimationTrack:Play()

		wait(3) 

		activeCooldown = false 
	end
end)

thanks, needed to revise to make it a bit more understandable lol

11 comments

0

you mean like a sword?

0

Yes, but I dont want the "sword" to deal damage if its not even moving, but when the animation plays.

0

there you go

0

its a custom made tool though, not a sword

0

I'm having the same problem, this is the default sword script, even if the HAMMER isn't moving, it still deals damage. Right back to square one..

0

should've given more context

0

You need to make it more descriptive

0

Tho the script only deal damage when your animation started

0

I already tested it myself

0

AHA! My bad, I forgot I was supposed to replace the original script. lol

0

-_-

1 answer

✓ Accepted answer

If you want a sword then, Here you go...

local Tool = script.Parent
local Animation = Tool.Animation
local activeCooldown = false
local cooldownTime = 3 
local Blade = script.Parent.Handle -- HitPart
local Damage = 10 -- Damage

Tool.Activated:Connect(function()
	if (activeCooldown) then
		return 
	else
		activeCooldown = true 

		local Character = Tool.Parent
		local Humanoid = Character.Humanoid

		local AnimationTrack = Humanoid:LoadAnimation(Animation)
		cooldownTime = AnimationTrack.Length

		AnimationTrack:Play()

		wait(3) 

		activeCooldown = false 
	end
end)

Blade.Touched:Connect(function(Hit)
	wait(1)
	if activeCooldown == true and Hit.Parent:FindFirstChild("Humanoid") then
		Hit.Parent:FindFirstChild("Humanoid").Health -= Damage
	else
		return
	end
end)

Hope It Helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.