here I’ll give you some idea of how you can do this
- You want the Animation for idle pose, Slash 1 and Slash 2
- and of course Your sword! try put all the animation in the place you can easily access
Now for the coding part
first we making so when the player equip the tool. the idle animation play
llocal Sword = script.Parent
local AnimationFolder = Sword.Animations
local player
local Humanoid
local Animator
local SlashTrack
local IdleTrack
local SlashCount = 1
Sword.Equipped:Connect(function()
player = Sword.Parent
Humanoid = player:WaitForChild("Humanoid")
Animator = Humanoid:WaitForChild("Animator")
IdleTrack = Animator:LoadAnimation(AnimationFolder.Idle)
IdleTrack:Play()
end)
Sword.Unequipped:Connect(function()
IdleTrack:Stop()
end)
Look! We now have a custom idle pose which all the slash animation will return to
now to make the sword slashing we just need to use .Activated
function but that will just swing the sword normally, we don’t do that here!
Sword.Activated:Connect(function()
if Debounce then return end
Debounce = true
SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
SlashTrack:Play()
wait(SlashTrack.Length)
Debounce = false
if SlashCount == 1 then
SlashCount = 2
else
SlashCount = 1
end
end)
Now we slashing!
but you may notice that the animation feel a little stiff and you can’t really do a slash combo with this
so let’s change that with GetMarkerReachedSignal
now what I didn’t tell you before is I put some animation event for use later while making animation for the sword
We’ll set debounce to false when it reached “Finish” marker so the sword won’t go back to the original pose before another slash is done this will replace wait()
Sword.Activated:Connect(function()
if Debounce then return end
Debounce = true
SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
SlashTrack:Play()
SlashTrack:GetMarkerReachedSignal("Finish"):Connect(function()
Debounce = false
end)
if SlashCount == 1 then
SlashCount = 2
else
SlashCount = 1
end
end)
Now we Slashing! 2.0 without an anoying pause between animation
Fully script
local Sword = script.Parent
local AnimationFolder = Sword.Animations
local player
local Humanoid
local Animator
local SlashTrack
local IdleTrack
local SlashCount = 1
local Debounce = false
Sword.Equipped:Connect(function()
player = Sword.Parent
Humanoid = player:WaitForChild("Humanoid")
Animator = Humanoid:WaitForChild("Animator")
IdleTrack = Animator:LoadAnimation(AnimationFolder.Idle)
IdleTrack:Play()
end)
Sword.Unequipped:Connect(function()
IdleTrack:Stop()
end)
Sword.Activated:Connect(function()
if Debounce then return end
Debounce = true
SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
SlashTrack:Play()
SlashTrack:GetMarkerReachedSignal("Finish"):Connect(function()
Debounce = false
end)
if SlashCount == 1 then
SlashCount = 2
else
SlashCount = 1
end
end)
Feel free to ask me if you have further question
Ps.: (I forgot to talk about another Animation Event which is call “Hit” but that is for creating a hitbox, in this post I’m only cover the animation)