Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Team uniform script, why am I getting a nil error using dictionary?

I'm trying to make a team uniformer script, I've not quite got it. I'll add in comments below.

function RenameTeams() -- This function renames all the teams, as the user-friendly system lets them simply copy the template.
	for i,v in pairs(script.Parent:GetChildren()) do
		v.Name = "Team "..i
	end
end

TeamTable = {} -- Where I store teams and uniforms as a dictionary, e.g ["White Shirt"] = 103021030

function ConfirmTeam(Colour) -- Used to return a colour to the next loop
	local Found = nil
	for i,v in ipairs(script:GetChildren()) do
		if v.Value == Colour then
			Found = v
		end
	end
	return Found
end

for i,v in ipairs(game.Teams:GetTeams()) do -- This function indexes all the teams' uniforms and their colour.
	table.insert(TeamTable, tostring(v.TeamColor).." Shirt", ConfirmTeam(v.TeamColor)[tostring(v.TeamColor).."Shirt ID"] - 1)
	table.insert(TeamTable, tostring(v.TeamColor).." Pants", ConfirmTeam(v.TeamColor)[tostring(v.TeamColor).."Pants ID"] - 1) 
end

for i,v in ipairs(TeamTable) do
	print(v)
end


game.Players.PlayerAdded:connect(function (Player)
	Player.CharacterAdded:connect(function (Character)
		Player.AppearanceLoaded:connect(function ()
			Player.Shirt.ShirtTemplate = "rbxassetid://"..TeamTable[Player.TeamColor]
			Player.Shirt.PantsTemplate = "rbxassetid://"..TeamTable[Player.TeamColor] -- Here, we search the colour from the table and find the uniform, then add it.
		end)
	end)
end)

I get this error:

Workspace.Script:30: attempt to index a nil value

For reference, line 30 begins on line 20 in the question.

1 comment

0

I am very confused what you are trying to accomplish on line 20, because that is not how you use table.insert.

1 answer

table.insert shouldn't be like how it is on line 20.

This discussion is preserved as it was. New answers, comments, and votes are closed.