How to make a roblox sword with animations?

How do I make a roblox sword with some animations? The animations includes equipping and sword swinging animations.

If you can help me that would be greatly appreciated :smiley:

3 Likes

This is quite easy to do! I am going to assume that you know how to make animations! After making these animations, store it into an Animation object and rename it to ‘Swing’ (that’s a demo name :wink: )

Equip Script (local script in tool):

local tool = script.Parent -- Gets the tool
local player = game:GetService("Players").LocalPlayer --Gets the player that is holding the tool
local character = player.Character -- Gets the player's character model
local animation = tool:WaitForChild("Equip") -- Checks for the animation
local animationTrack = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- Loads the animation for it to be ready to use!
--Equip
tool.Equipped:Connect(function()
     animTrack:Play() -- Play animation when equipped. If you want the animation to be a loop, make sure to click the loop icon when creating the animation!
end)
--Unequip
tool.Unequipped:Connect(function()
     animTrack:Stop() -- Stops the animation
end)

Sword Swing (In the same script as above):

local animationSw = tool:WaitForChild("Swing") -- Checks for the animation. 
local animationTrackSwing = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- Loads the animation for it to be ready to use!

tool.Activated:Connect(function()
 animationTrackSwing:Play() -- Make sure this isn't a looped animation!
end)

Full Script:

local tool = script.Parent -- Gets the tool
local player = game:GetService("Players").LocalPlayer --Gets the player that is holding the tool
local character = player.Character -- Gets the player's character model
local animation = tool:WaitForChild("Equip") -- Checks for the animation
local animationTrack = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- Loads the animation for it to be ready to use!
--Equip
tool.Equipped:Connect(function()
     animTrack:Play() -- Play animation when equipped. If you want the animation to be a loop, make sure to click the loop icon when creating the animation!
end)
--Unequip
tool.Unequipped:Connect(function()
     animTrack:Stop() -- Stops the animation
end)
local animationSw = tool:WaitForChild("Swing") -- Checks for the animation. 
local animationTrackSwing = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- Loads the animation for it to be ready to use!

tool.Activated:Connect(function()
 animationTrackSwing:Play() -- Make sure this isn't a looped animation!
end)

Hope this helped you out!

9 Likes

Thank you! This helped me out, epicly :happy3:!

Also do you know how to make a sword idle anim, and how to put it in a script? I’m sorry if I’m asking too much

Basically, you would create an animation for the idle anim and set it to loop. Then go to animation properties and set that to idle. Export it to roblox and copy the id. Then create an Animation object and paste the id into the asset id section. You now have an animation!

Also, never worry about asking too much! Asking is the way to learn!

Oh I meant making an idle animation and implementing it into a script

Hmm… What do you mean be implementing into a script? Do you mean having a constant loop for the idle animation when the tool is equipped?

If so, after the equip animation, you would play the idle animation. Since the idle animation is a constant loop, it won’t stop playing until you tell it to stop!

I’m sorry, but I still do not understand! What do you want to achieve? How will it inflict the player?

I want the player to have an idle animation when holding the sword, like maybe he holds the sword a different way.

1 Like

On the .Equipped even you could create a loop

while true do
  if idle then
    idleAnim:Play()
    idleAnim.Stopped:Wait()
  end
end

the idle would be a local variable and on .Activated & .Unequipped you would set it to false (on Activated wait until the animation finishes and set it back to true)

1 Like