Need help with my animations (Sword Combat System)

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a sword combat system.

  2. What is the issue? Include screenshots / videos if possible!
    The animations don’t play.


    (I was clicking)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I don’t think I need to search a website for that.

-- Wait for char
game.Players.LocalPlayer.CharacterAdded:Wait()

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")

-- Modules
local Config = require(script.Parent.Parent.Modules.Config)

-- Tool
local Tool = script.Parent.Parent
local Handle = Tool:WaitForChild("Handle")

-- UI
local UI = Tool.Assets.UI
local CooldownUI = UI.CooldownUI

-- Sword Vars
local Damage = Config.Damage
local Cooldown = Config.Cooldown

-- Player Vars
local player, humanoid, char
char = Tool.Parent.Parent or Players.LocalPlayer.CharacterAdded:Wait() or Players.LocalPlayer.Character
player = Players.LocalPlayer
humanoid = player.Character:WaitForChild("Humanoid")

-- Anim Folder
local AnimFolder = Tool.Animations

-- Booleans
local isAttacking = false
local canDamage = true

-- Animation Instances

for i,v in pairs(Config.Animations.SlashAnimations) do
	if not v.Enabled then continue end
	
	local Anim = Instance.new("Animation")
	Anim.Parent = AnimFolder
	Anim.Name = i
	Anim.AnimationId = v.AnimationId
end

for i,v in pairs(Config.Animations.OtherAnimations) do
	if not v.Enabled then continue end
	
	local Anim = Instance.new("Animation")
	Anim.Parent = AnimFolder
	Anim.Name = i
	Anim.AnimationId = v.AnimationId
end


local function onEquip()
	local EquipAnim = AnimFolder:WaitForChild("Equip")
	local EquipTrack = humanoid:LoadAnimation(EquipAnim)
	EquipTrack:Play()
end

-- Attack
local Combo = 1

local function Attack()
	local Slash = humanoid:LoadAnimation(AnimFolder:WaitForChild("Slash" .. tostring(Combo)))
	Slash:Play()
	
	Tool.Remotes.ClientCast:FireServer(Slash.Length, Config.Cooldown)
	canDamage = false
	task.wait(math.max(Slash.Length, Config.Cooldown))
	canDamage = true
end

UserInputService.InputBegan:Connect(function(input, gameProccessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and char:FindFirstChild(Tool.Name) then
			if isAttacking == false and canDamage then
				isAttacking = true

				if Combo > 5 then
					Combo = 1
				end

				Attack()

				isAttacking = false
				Combo += 1
			
			end
	end
end)

Tool.Equipped:Connect(onEquip)

This script is the whole local script. The slash animations are played from the Attack() function.

Have you tried loading the animations after the animation is created in the AnimFolder?

for i,v in pairs(Config.Animations.SlashAnimations) do
	if not v.Enabled then continue end
	
	local Anim = Instance.new("Animation")
	Anim.Parent = AnimFolder
	Anim.Name = i
	Anim.AnimationId = v.AnimationId
	humanoid:WaitForChild("Animator"):LoadAnimation(Anim)
end

Another possible issue could be that the AnimationIDs arent being set correctly.

If I do that, how am I supposed to play the animation though?

Here’s a list of things to check off to debug:

  • Is the animation priority set to “Action”?
  • Is the animation looped and meant to be a pose? If so, make sure it is looping.
  • Is the weight of the animation correct?
  • Is the animation owned by you? If not, try playtesting in team test.
  • Is the animation owned by your group, and the game is owned by you? If so, reupload your animation.
  • Does the animation load if you set it as the default walk animation?

If all of the above works, and recompiling your animation doesn’t, I don’t know what to tell you.

I fixed it. I just needed to do that:
image

1 Like