"attempt to index nil with 'ApplyDescription'" error when applying team NPC appearance to players

Heya everyone!

I’m working on a class-based shooter game and I’m trying to apply players their respective team character (BLOXXER’s players look like a stereotypical brickbattler while PWNER’s look identical albeit with a blue torso). The issue being that every time I tried applying the humanoid descriptions of the characters to the players, I always seem to get an error message. By the way, this code is a snippet of a ServerScriptService script.

-- // Teams
local RED = TEAMS.RED
local BLU = TEAMS.BLU
local NEUTRAL = TEAMS.NEUTRAL

local BLOX = ServerStorage:WaitForChild("TEAM_NPC_FOLDER").RED
local PWND = ServerStorage:WaitForChild("TEAM_NPC_FOLDER").BLU
local BLOX_HumanoidDescription = BLOX.Humanoid:GetAppliedDescription()
local PWND_HumanoidDescription = PWND.Humanoid:GetAppliedDescription()

local REDCount = 0
local BLUCount = 0

-- // Inserting Team
PLRS.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Char)
		for _, Player in pairs(PLRS:GetPlayers()) do
			local Player_Humanoid = Player:FindFirstChildWhichIsA("Humanoid")
			
			if REDCount <= BLUCount then
				Player.Team = RED
				Player.TeamColor = RED.TeamColor
				REDCount = REDCount + 1
				
				-- Apply the BLOX's humanoid description to the player
				local description = Instance.new("HumanoidDescription")
				description:Clone(BLOX_HumanoidDescription)
				Player_Humanoid:ApplyDescription(description)
			else
				Player.Team = BLU
				Player.TeamColor = BLU.TeamColor
				BLUCount = BLUCount + 1
				
				-- Apply the PWND's humanoid description to the player
				local description = Instance.new("HumanoidDescription")
				description:Clone(PWND_HumanoidDescription)
				Player_Humanoid:ApplyDescription(description)
			end
			
			-- Load the character with the new humanoid description
			Player:LoadCharacter()
		end
	end)
end)

You’re trying to get the players humanoid from the player object instead of the character model, do this instead:

local Player_Humanoid = Player.Character:FindFirstChildWhichIsA(“Humanoid”)

I don’t think that’s the problem here, “index nil” means it can’t find something or it doesn’t exist. I would try to parent the humanoid descriptions because they aren’t parented anywhere.

The index nil error doesn’t mean it can’t find something, it means that you’re subscripting a nil value. And humanoid is indexed with ApplyDescription which means humanoid is nil.

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