Ad
Log in to vote
0

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

Asked by 13 days ago
Edited 13 days ago

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

0
you mean like a sword? The_Saver31 257 — 13d
0
Yes, but I dont want the "sword" to deal damage if its not even moving, but when the animation plays. kingsworld9 4 — 13d
0
there you go The_Saver31 257 — 13d
0
its a custom made tool though, not a sword kingsworld9 4 — 13d
View all comments (7 more)
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.. kingsworld9 4 — 13d
0
should've given more context kingsworld9 4 — 13d
0
You need to make it more descriptive The_Saver31 257 — 13d
0
Tho the script only deal damage when your animation started The_Saver31 257 — 13d
0
I already tested it myself The_Saver31 257 — 13d
0
AHA! My bad, I forgot I was supposed to replace the original script. lol kingsworld9 4 — 13d
0
-_- The_Saver31 257 — 13d

1 answer

Log in to vote
0
Answered by 13 days ago

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!

Ad

Answer this question