How would i make different sword hit animations?

Hi. I would like to make something like this:

How would i make different hit animations? I want to achieve the post above and i was wondering how to do this.

I only have ONE hit animation, and i want to add more.

1 Like

As in random animations each hit?

You can create more animations and put them in a folder

Yes. i want to achieve that

ignore me

Bread

you could either put them in a folder like the guy said up top or you can do this local RandomAnimations = {‘animation id’,‘animation id’}
local RandomAnimationChance = RandomAnimations[math.random(1,2)]

i am not sure if this is a good way since i am still learning how to script but thats how i did it

I’m pretty sure that wont work.

well you then you’d set the animations id to the RandomAnimationChance part since it grabbed a animation id from the table

(with the animation ids being the animations you uploaded)

1 Like

Uh, code example?

Summary

This text will be hidden

i got to go but i will reply later unless someone else replys during that time (sorry)

An example:

local Animations = script.Parent:FindFirstChild("AnimationsFolder")
local Tool = script.Parent

Tool.Activated:Connect(function()
    local randomAnimation = Animations:GetChildren()[math.random(1,#Animations:GetChildren()]
    print(randomAnimation) 
    --Play that animation, etc.
end)
local Animations = {
	"rbxassetid://123456789",
	"rbxassetid://123456789",
	"rbxassetid://123456789"
}

script.Parent.Activated:Connect(function()
	local Character = script.Parent.Parent
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	
	local RandomAnimation = Animations[math.random(1, #Animations)]
	
	local LoadedAnimation = Humanoid.Animator:LoadAnimation(RandomAnimation)
	LoadedAnimation:Play()
end)
1 Like

None of the solutions work.

Here is a fixed version of that script:

local Animations = {
	"rbxassetid://123456789",
	"rbxassetid://123456789",
	"rbxassetid://123456789"
}

script.Parent.Activated:Connect(function()
	local Character = script.Parent.Parent
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	
	local AnimationInstance = Instance.new("Animation")
	local RandomAnimation = Animations[math.random(1, #Animations)]
	AnimationInstance.AnimationId = RandomAnimation 
	
	local LoadedAnimation = Humanoid.Animator:LoadAnimation(AnimationInstance)
	LoadedAnimation:Play()
end)

This should work now, if it doenst ill review it for any issues.

1 Like

Serverscript or Localscript?

Either works, because animations played locally are shown globally.

It works now, thanks!