5 is a invalid member of folder

In the process of making a blocking system and it was going pretty good up until now…
so when u punch someone 4 times, it breaks their block and plays an animation
but when i attempt to play this animation, it tells me it is not a valid member of the folder i have placed it in. line 86, error is as follows: 5 is not a valid member of Folder

Code:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("Combat")

local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")

local Animations = script:WaitForChild("Animations")
local enemyAnimations = script:WaitForChild("EnemyAnimations")
local Meshes = script:WaitForChild("Meshes")


local anims = {
	
	Animations:WaitForChild("P1"),
	Animations:WaitForChild("P2"),
	Animations:WaitForChild("P3"),
	Animations:WaitForChild("P4"),
}

local enemyAnims = {
	
	enemyAnimations:WaitForChild("H1"),
	enemyAnimations:WaitForChild("H2"),
	enemyAnimations:WaitForChild("H1"),
	enemyAnimations:WaitForChild("H2"),	
	enemyAnimations:WaitForChild("BlockBreak"),
}


local limbs = {
	
	"Right Arm",
	"Left Arm",
	"Right Leg",
	"Left Leg",
	
}

local Damage = 10

remote.OnServerEvent:Connect(function(player,count)
	
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	local attack = humanoid:LoadAnimation(anims[count])
	attack:Play()
	
	local limb = character:WaitForChild(limbs[count])
	
	local folder = Instance.new("Folder",character)
	folder.Name = player.Name.." Melee"
	
	local Hitbox = Meshes:WaitForChild("Hitbox"):Clone()
	Hitbox.CFrame = limb.CFrame
	Hitbox.Size = limb.Size
	Hitbox.Material = Enum.Material.Neon
	Hitbox.Parent = folder
	Debris:AddItem(Hitbox,.5)
	
	local weld = Instance.new("ManualWeld")
	weld.Part0 = Hitbox
	weld.Part1 = limb
	weld.C0 = weld.Part0.CFrame:toObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	
	Hitbox.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			if not hit:IsDescendantOf(character) then
				
				local enemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
				local enemyRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
				
				
				if enemyHumanoid and enemyRootPart then
					
					local blockAction = enemyHumanoid:FindFirstChild("blockAction")
					
					if blockAction then
						Hitbox:Destroy()
						
						if blockAction.Value > 0 then
							blockAction.Value = blockAction.Value - 1
							if blockAction.Value == 0 then
								local Break = enemyHumanoid:LoadAnimation(enemyAnimations[5])
								Break:Play()
							end
						end
						
					else
						Hitbox:Destroy()
						
						enemyHumanoid:TakeDamage(Damage)
						
						local reaction = enemyHumanoid:LoadAnimation(enemyAnims[count])
						reaction:Play()
						
						if count == 4 then
							enemyRootPart.Anchored = true
							local goal = {}
							goal.CFrame = CFrame.new((rootPart.CFrame * CFrame.new(0,0,-12)).p,rootPart.CFrame.p)
							local info = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
							local tween = TweenService:Create(enemyRootPart,info,goal)
							tween:Play()
							
							tween.Completed:Connect(function()
								enemyRootPart.Anchored = false
							end)
						end						
					end		
				end
			end
		end
	end)
	
	
	
	remote.FireClient(remote,player)
	
end)

Can you send a screenshot of what the folder heirarchy looks like?

image

Can I ask which line is the line 86?

local Break = enemyHumanoid:LoadAnimation(enemyAnimations[5])
1 Like

Ah I see, thank you for the help.

2 Likes

local Break = enemyHumanoid:LoadAnimation(enemyAnimations.BlockBreak)

1 Like

Well enemyAnimations is a folder and not a table since u never used GetChildren()

1 Like
local Break = enemyHumanoid:LoadAnimation(enemyAnimations[5])

Before I say anything I don’t know if this is the right solution but I think enemyAnimations[5] was supposed to be enemyAnims[5] here.

1 Like

change the line 6
local enemyAnimations = script:GetChildren("EnemyAnimations")

and here is a mistake

enemyHumanoid:LoadAnimation(enemyAnimations[5])
you require the fifth children in the folder when you have just 3
you could just require the specific animation or [3]

1 Like

AHHHHHH THANK YOU, man i swear it’s always something simple