Animation not playing (sword)

Hi, I have a module script that runs client for swords. I am having a issue where I can’t play an animation that is already loaded because it is “nil”.

At Client:M1, there is an error in: self.LoadingAnimations[attackString]:Play()

I also outputted self.LoadedAnimations in the method. Here is the output:

{
                    ["Attack1"] = Attack1,
                    ["Attack2"] = Attack2,
                    ["Attack3"] = Attack3,
                    ["Equip"] = Equip,
                    ["Idle"] = Idle
                 }

I can load equip but I can’t load the attacks…

ERROR:

 02:11:05.118  ReplicatedStorage.Source.Classes.ClassAbilities.Reaper.Client:78: attempt to index nil with 'Attack1'  -  Client - Client:78

Here’s the module:

local Client = {}
Client.__index = Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService('RunService')

local ContextActionService = require(ReplicatedStorage.Source.Modules.ContextActionUtility)
local RaycastHitbox = require(ReplicatedStorage.Source.Modules.RaycastHitboxV4)

local function PlaySound(Sound, Root)
	local soundClone = Sound:Clone()
	soundClone.Parent = Root
	soundClone:Play()

	game.Debris:AddItem(soundClone,3)
end

function Client.new(Tool: Tool, Character: Model, Animations: any)
	local self = setmetatable({},Client)

	self.Tool = Tool:Clone()
	self.Character = Character
	self.Humanoid = Character:WaitForChild("Humanoid")
	self.Root = Character:WaitForChild("HumanoidRootPart")
	self.Animations = Animations
	
	self.Settings = require(script.Parent.Settings)
	self.LoadedAnimations = {}
	self.Sounds = game:GetService("SoundService")[script.Parent.Name]
	
	self._combo = 1
	self._lastClicked = tick()
	
	for _, anim in pairs(self.Animations:GetChildren()) do 
		self.LoadedAnimations[anim.Name] =  self.Humanoid.Animator:LoadAnimation(anim)
		self.LoadedAnimations[anim.Name].Priority = Enum.AnimationPriority.Action3 -- highest priority
	end
	
	self.Slashing = self.Humanoid:GetAttribute("Slashing")
	self:Equip()
	
	Players.LocalPlayer.CharacterAdded:Connect(function()
		self:Equip()
	end)
	
	local function Attack()
		self:M1()
	end
	
	ContextActionService:BindAction("M1", Attack, true, Enum.UserInputType.MouseButton1)
	
	return self
end

function Client:Equip()
	self.LoadedAnimations.Equip:Play()
	self.LoadedAnimations.Idle:Play()
	
	PlaySound(self.Sounds["Equip"],self.Root)
end

function Client:M1()
	if self.Slashing then
		return
	end
	
	local attackString = "Attack"..tostring(self._combo)
	
	if tick() - self._lastClicked >= self.Settings["COMBO_RESET"] then
		self._combo = 1
	end
	
	self._lastClicked = tick() 
	
	self.Humanoid:SetAttribute("Slashing", true)
	
	self.LoadingAnimations[attackString]:Play()
	
	PlaySound(self.Sounds["M1"],self.Root)
	
	task.wait(self.Settings["M1_COOLDOWN"])
	
	if self._combo < self.Settings.COMBOS then
		self._combo += 1
	else
		self._combo = 1
	end
	
	self.Humanoid:SetAttribute("Slashing", false)
end

return Client
1 Like

Try this

function Client:M1()
	if self.Slashing then
		return
	end
	
	local attackString = "Attack"..tostring(self._combo)
	
	if tick() - self._lastClicked >= self.Settings["COMBO_RESET"] then
		self._combo = 1
	end
	
	self._lastClicked = tick() 
	
	self.Humanoid:SetAttribute("Slashing", true)
	
	self.LoadedAnimations[attackString]:Play() 
	
	PlaySound(self.Sounds["M1"],self.Root)
	
	task.wait(self.Settings["M1_COOLDOWN"])
	
	if self._combo < self.Settings.COMBOS then
		self._combo += 1
	else
		self._combo = 1
	end
	
	self.Humanoid:SetAttribute("Slashing", false)
end
2 Likes

lololollolll I must have been really tired if I didn’t notice that. Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.