Possible to use variables to define key in dictionary?

Hey, so I’m trying to make a script that will automatically save the same data from each gameslot a player has , and add the corresponding number to the key name. For example, if the player had 2 gameslots, it would save two character names, called GameSlot1CharacterName and GameSlot2CharacterName

I tried this, but the way I’ve defined them is incorrect as you can probably tell. How can I fix this?

local number = player.PlayerDataFolder.NumberOfLives.Value
		wait()
		repeat
		local gameslotdatatobesaved = {
			"GameSlot" .. number .. "CharacterName" = player.PlayerDataFolder:FindFirstChild("GameSlot" .. number .. "").CharacterName.Value
            "GameSlot" .. number .. "SkinColor" = player.PlayerDataFolder:FindFirstChild("GameSlot" .. number .. "").SkinColor.Value
		}
			mystore:SetAsync(playerid,gameslotdatatobesaved)
		wait()
        number = number - 1
		until
		number == 0
1 Like

To properly make a string an index.

local dict = {
    ["your string here".. "you can do operations here!"] = value,
    [`GameSlot{number}CharacterName`] = "me"
}

-- or

local dict2 = {
   index = 1,
   anotherindex = 2
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.