(Error: Attempt to call a table value) Comes up when I try to run animation script

Hi! Basically, I have made some animations today for my game along with a couple of scripts and a RemoteEvent to trigger it. So, what happens is when you click it plays the animation on the player if you get what I mean. However, when I run it, it says in the output: ServerScriptService.CombatSystem:12: attempt to call a table value.

Here is the script apparently has an error in line 12:

local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")

local Animations = script:WaitForChild("Animations")

local anims = {Animations:WaitForChild("Right"), Animations:WaitForChild("Left"), Animations:WaitForChild("Gut"), Animations:WaitForChild("Kick"),}

Combat.OnServerEvent:Connect(function(player,count)
    local Character = player.Character
    local humanoid = Character:WaitForChild("Humanoid")

    local attack = humanoid:LoadAnimations(anims(count))
    attack:Play()

    Combat:FireClient(player)
end)

Here is what it looks like in the explorer tab:
image
So just a RemoteEvent called Combat in RepStorage, a script called CombatSystem with a folder containing all the animations, and in StarterPack which is a localscript. (Btw its just the moon animator saves contained in ServerStorage).

If you would like the Localscript in StarterPack this is it, even though there isn’t anything wrong with it:

local Player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")

local UIS = game:GetService("UserInputService")

local debounce = false
local cd = .25

local currTime = 0
local prevTime = 0
local count = 0

UIS.InputBegan:Connect(function(input,isTyping)
    if isTyping then
	    return
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
	    if debounce == false then
		    debounce = true	
		    currTime = tick()
		
		    local passedTime = currTime - prevTime
		    if passedTime < 1 then
			     --Can continue the combat combo
			    count = count + 1
			    if count > 4 then
				    count = 1
			    end
		    else
			    --Restarts the combo
			    count = 1
		    end
		
		    Combat:FireServer(count)
		
	    end
    end
end)

The Combat localscript in StarterPack seems to be perfectly fine, its just the CombatSystem script that has an issue on line 12.

So, just to make it clear, the when I try run the game to get the player to play the animations when clicking, this message comes up in output:

ServerScriptService.CombatSystem:12: attempt to call a table value.

How would I fix this, any help is really appreciated!

Thanks a lot, DannyGT7

2 Likes

Change:
local attack = humanoid:LoadAnimations(anims(count))

To this:
local attack = humanoid:LoadAnimations(anims[count])

4 Likes

Thank you so much!!! Duh, my bad, should have realised that! Thanks for all the help!!! Really appreciated!

No problem glad it worked! Goodluck with your project.

1 Like

Thank you so much, really appreciated! Thank you!!! :smiley: