-
What do you want to achieve? Keep it simple and clear!
I want to make a sword combat system. -
What is the issue? Include screenshots / videos if possible!
The issue is that I get the error:attempt to index nil with 'LoadAnimation' -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to look for solutions on devForum, but for some reason they didn’t work for me or I am missing something.
The problem is happening in the Local Script
-- 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
player = Players:GetPlayerFromCharacter(char)
humanoid = char:FindFirstChild("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 then
if char:FindFirstChild(Tool.Name) and char[Tool.Name]:IsA("Tool") then
if isAttacking == false and canDamage then
isAttacking = true
if Combo > 5 then
Combo = 1
end
Attack()
--[[local Slash1Track = humanoid:LoadAnimation(AnimFolder:WaitForChild("Slash1"))
Slash1Track:Play()
Caster:Start()
Caster.HumanoidCollided:Connect(function(result, hithumanoid)
if db[hithumanoid] then return end
db[hithumanoid] = true
hithumanoid:TakeDamage(Config.Damage)
wait(.2)
db[hithumanoid] = false
end)
Caster:Stop()
wait(math.max(Slash1Track.Length, Config.Cooldown))]]
isAttacking = false
Combo += 1
end
elseif not char:FindFirstChild(Tool.Name) and not char:FindFirstChildWhichIsA("Tool") then
return
end
end
end)
Tool.Equipped:Connect(onEquip)



