Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
Edited 8 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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.

0
I am very confused what you are *trying* to accomplish on line 20, because that is not how you use table.insert. BlueTaslem 18071 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

Ad

Answer this question