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

How can I print indexes from a dictionary table? [ANSWERED]

I have this script:

local teamstable = {
	Teams = {
		[1] = {
			Name = "Inmate",
			Description = game.Teams.Inmate.MenuStats.Description.Value
		},
		[2] = {
			Name = "Max Security Inmate",
			Description = game.Teams["Max Security Inmate"].MenuStats.Description.Value
		},
		[3] = {
			Name = "Supermax Inmate",
			Description = game.Teams["Supermax Inmate"].MenuStats.Description.Value
		},
		[4] = {
			Name = "Medical Staff",
			Description = game.Teams["Medical Staff"].MenuStats.Description.Value
		},
		[5] = {
			Name = "Facility Security",
			Description = game.Teams["Facility Security"].MenuStats.Description.Value
		},
		[6] = {
			Name = "Nervex Security",
			Description = game.Teams["Nervex Security"].MenuStats.Description.Value
		},
		[7] = {
			Name = "Emergency Response Team",
			Description = game.Teams["Emergency Response Team"].MenuStats.Description.Value
		},
		[8] = {
			Name = "Prison Administration",
			Description = game.Teams["Prison Administration"].MenuStats.Description.Value
		},
		[9] = {
			Name = "Prison Command",
			Description = game.Teams["Prison Command"].MenuStats.Description.Value
		},
		[10] = {
			Name = "CPU",
			Description = game.Teams.CPU.MenuStats.Description.Value
		},
		[11] = {
			Name = "Special Forces",
			Description = game.Teams["Special Forces"].MenuStats.Description.Value
		},
		[12] = {
			Name = "Military Police",
			Description = game.Teams["Military Police"].MenuStats.Description.Value
		},
		[13] = {
			Name = "Hostile Forces",
			Description = game.Teams["Hostile Forces"].MenuStats.Description.Value
		},
		[14] = {
			Name = "Moderation Team",
			Description = game.Teams["Moderation Team"].MenuStats.Description.Value
		},
		[15] = {
			Name = "Prison Intelligence",
			Description = game.Teams["[EXPUNGED]"].MenuStats.Description.Value
		},
		[16] = {
			Name = "Government Staff",
			Description = game.Teams["Government Staff"].MenuStats.Description.Value
		},
		[17] = {
			Name = "Engineering & Technical",
			Description = game.Teams["Engineering and Technical"].MenuStats.Description.Value
		},
	}
}

wait(20)
for i, val in pairs(teamstable.Teams[15]) do
	print(val.Description)
end

And when the 20 second wait is over, it prints nil (x2) How can I fix this?

5 comments

0

val already refers to the attributes Name & Description during iteration, as you're traversing through the contents of teamtable.Teams[15]. Simply running print(val) will reveal the content, or by directly indexing the description element: teamtable.Teams[15].Description 

0

try print(i) instead of print(val.Description)

0

the way you have it setup, each index inside Teams is a table, so you're looping through the 15th table so to get whats inside the table, use the 2 indexes inside (Name and Description). The associated value for each index is what it's equal to.

1

why are you looping when you could do print(teamstable.Teams[15].Description)

0

^

1 answer

greatneil80 has "answered" my question. They said I could do print(teamstable.Teams[15].Description which works perfectly. Thank you!

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