Get key name with key contents

would that change how it goes into the dictionary though

No, that’d be table.insert()

You’re attempting to find if a Race’s Name is not valid to the RaceData so you can change its values to them

Tables are definitely fun

Yeah I used table.find() instead and it still printed ā€œ1ā€ and ā€œNumberOfRacersā€ for index,value of the RoadRace dictionary

Well, somewhere in there you’re still referencing the square brackets if it’s indexing back as numbers

Could you at least show the script that handles everything?

Yeah hold on.

 local RaceModule = require(game.ServerScriptService.ServerScripts.RaceModule)

 local Races = game.workspace.Races:GetChildren()

 RaceModule.InitiateRaceData(Races)

This is the server script handler.

 function RaceModule.InitiateRaceData(races)
     if RaceSettings.TimeTrialMode == false then
		for _, race in pairs(races) do
			print(table.find(RaceData,race.Name))
			if table.find(RaceData, race.Name) == nil then
         RaceData[race.Name] = {
         PlayersEnrolledInRace = {},
         RaceMax = RaceSettings.NonTimeTrialModeMaxRacerCount,
         NumberOfRacers = 0,
         PlayersReadyForRace = 0,
					StartTime = 0,
					RaceStarted = false,
         }
     end
     end
 elseif RaceSettings.TimeTrialMode == true then
		for _, race in pairs(races) do
			print(table.find(RaceData, race.Name))
			if table.find(RaceData, race.Name) == nil then
         RaceData[race.Name] = {
         PlayersEnrolledInRace = {},
         RaceMax = 1,
         NumberOfRacers = 0,
         PlayersReadyForRace = 0,
					StartTime = 0,
					RaceStarted = false
         }
     end
     end
 end
 end

This is RaceModule ^^

Note: Racesettings is another module with just settings, TimeTrialMode is on.

I also have a place in the module where this line is

				RaceData[race.Name].PlayersEnrolledInRace[tostring(_)].HasStartedRace = true

ā€œ_ā€ is the player name, it is referencing the playername in PlayersEnrolledInRace.

I think I found the easiest way to describe what I need.

local dictionary = {
["Apple"] = {
color = "red"
numbers = 5
}
["Orange"] = {
color = "red"
numbers = 5
}

}

This is the dictionary, if i did print(Dictionary.Orange), it would print its color and numbers. what if i wanted it to print Orange

In other words, is there a name property for the key.

There isn’t a Name property for keys/indexes, I’m just lost on how to handle the situation

You’ll have to loop through the table, referencing its custom index values

Also, I know this is offtopic, but if you do Dictionary[ā€œhiā€] to make a new key in the dictionary, does it put it ANYWHERE in the dictionary, or in order( so at the end of the dictionary )

Not exactly sure, but my assumption is that it puts it anywhere in the Dictionary since it’s not based on order

Ah alright thank you! And thanks for the help with the loop i forgot I could loop through it

1 Like