Attempt to index nil with 'Shirt'

Hello, I have made another topic related to this script but now Its different, since this time it just says that the Shirt object is nil in the character, could I get some help? And here is the code:

-- // Variables \\ --
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local _ClothingLibrary = require(script.ClothingLibrary)

-- // Main Code \\ --
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player:GetRankInGroup(4178207) == 6 or 7 or 9 then 		-- Hostpitality Outfit
			Character:WaitForChild("Shirt").ShirtTemplate = _ClothingLibrary.Low_Rank.Shirt
			Character:WaitForChild("Pants").PantsTemplate = _ClothingLibrary.Low_Rank.Pants
		elseif not Character:WaitForChild("Shirt") and Player:GetRankInGroup(4178207) == 6 or 7 or 9  then
			local Shirt = Instance.new("Shirt", Character)
			Shirt.ShirtTemplate = _ClothingLibrary.Low_Rank.Shirt
		elseif not Character:WaitForChild("Pants") and Player:GetRankInGroup(4178207) == 6 or 7 or 9  then
			local Shirt = Instance.new("Pants", Character)
			Shirt.ShirtTemplate = _ClothingLibrary.Low_Rank.Pants
		elseif Player:GetRankInGroup(4178207) == 8 then 			-- Chef Outfit
			Character:WaitForChild("Shirt").ShirtTemplate = _ClothingLibrary.Culinary.Shirt
			Character:WaitForChild("Pants").PantsTemplate = _ClothingLibrary.Culinary.Pants
		end
	end)
end)

You’re telling the code to wait for the Shirt’s Template to be a Shirt, rather than the ShirtTemplate - same with the pants. For your scenario:

			Character:WaitForChild("Shirt").ShirtTemplate = _ClothingLibrary.Low_Rank.Shirt.ShirtTemplate -- Added ShirtTemplate
			Character:WaitForChild("Pants").PantsTemplate = _ClothingLibrary.Low_Rank.Pants.PantsTemplate -- Added PantsTemplate

Not really, in my situation ClothingLibrary is a module where are the clothing ids stores, here is the module.

local module = {
	["Hostpitality"] = {
		Shirt = 'rbxassetid://5492204837',
		Pants = 'rbxassetid://5492207284',
	},
	
	["Culinary"] = {
		Shirt = 'rbxassetid://5507755012',
		Pants = 'rbxassetid://5498068965',
	},
}

return module

Hold on, you’ve created a new variable with “Shirt” that’s instanced with “Pants” on the line:

			local Shirt = Instance.new("Pants", Character)

Having it mixed with up with:

			Shirt.ShirtTemplate = _ClothingLibrary.Low_Rank.Pants

Attempt to change the ShirtTemplate to PantsTemplate, as you’re indexing it incorrectly.

Oh didn’t even notice, but still it says the error and I fixed it.

Is there a line the error is specifically pointing at?

It says at line 10, but basically line 10 is getting the player’s shirt and the shirt’s ShirtTemplate.

Line 10:

Character:WaitForChild("Shirt").ShirtTemplate = _ClothingLibrary.Low_Rank.Shirt

Attempt to index nil with 'Shirt' either means that the Low_Rank key doesn’t exist in the table, or the character doesn’t. The latter is unlikely since you’re using CharacterAdded.

There’s no Low_Rank shirt in this catalog.

3 Likes

Woah, thank you very much! I didn’t even observe that I didn’t change the Low_Rank to the correct ones, thank you!