Need help animating a sword

Hello, my name is rip_Zephyr, I’m currently making a sword swinging template for a future game. Sadly, I don’t know how to animate the sword. I’ve tried multiple things but they never worked. Here is my code:

local sword = script.Parent

local function swordEquipped()
canBeUsed = true
end

local function swordActivated()
	if canBeUsed == true then
		-- I want the code that plays the animation to go here
		-- The Animation ID is "rbxassetid://18179893944" 
	end
end

sword.Equipped:Connect(swordEquipped)
sword.Activated:Connect(swordActivated)

If anyone knows how to do this please reply down below this is a competition with my friend on who can make the best game and I seriously want to win because I have better grades than him.

3 Likes

Create an animation instance with the animation ID, find or create an animator in the humanoid, load the animation, and play it.

1 Like

Im making a sword, a sword is a tool, and a tool doesn’t have a humanoid, so that wouldn’t work.

Why would you want to animate the sword?

If you click on a sword you need a swing animation otherwise it looks weird

Just animate the character swinging?

wait
i am stupid
i forgot that the animation is for the character

1 Like

bruh i strangely thought my animation was for the sword not the player

1 Like

thank you for helping me realize this

1 Like

Oh yeah I know I sound kinda stupid for this but if you have time do you mind posting an example of this code i know what you mean but i dont know how to apply it


local sword = script.Parent -- Assuming the sword is a child of the tool
local tool = sword.Parent

local handle = sword:WaitForChild("Handle") -- Assuming the sword's handle is named "Handle"
local weld = Instance.new("Weld")
weld.Parent = handle
weld.Part0 = handle
weld.Part1 = tool:WaitForChild("Handle") -- Assuming the tool's handle is named "Handle"
weld.C0 = CFrame.new(0, 0, 0) -- Adjust this to position the sword in the player's hand

local swingAnimation = Instance.new("Animation")
swingAnimation.AnimationId = "rbxassetid://INSERT_ANIMATION_ID_HERE" -- Insert the animation ID for the swinging animation

local animator = humanoid:FindFirstChildOfClass("Animator")
local animationTrack = animator:LoadAnimation(swingAnimation)
animationTrack:Play()

1 Like

Go try it maybe will work to your script and add

it gives me an output error: 14:35:50.124 Players.Pish85.Backpack.Sword.Script:23: attempt to index nil with ‘FindFirstChildOfClass’

That is the greatest job ever ever

What do you need to check something happen?

forgot hand tools add something ideas good

maybe this is a bug but theres no output error however theres no animation

This was a great read for a first grade

maybe i need to remake my animation