I need help with transform system

So my friend send these list of character and I already have the characters model. I just wonder if there is any short ways to make a transform system without using hundreds of if statements when the player level up. I also have the level system too!!

List of characters:

Level 1 - Rareusernamee
Level 2 - rareusernameee
Level 3 - Guest_202O1
Level 4 - Guest498570
Level 5 - Jane Doe
Level 6 - stonefreeoh
Level 7 - wourequiem
Level 8 - tastyDora
Level 9 - zateezoverheaven
Level 10 - sirckly
Level 11 - AlexEmopunk
Level 12 - Adoptme1230player
Level 13 - Vesir204
Level 14 - fSG_GSf
Level 15 - galpalingpea
Level 16 - mighty3than
Level 17 - KingK251
Level 18 - balli08
Level 19 - YoBoyMateus121_YT
Level 20 - ixr_q
Level 21 - Irish_Wolftuber
Level 22 - bloodygrln
Level 23 - MatthyouNoah
Level 24 - PurpleRuby11
Level 25 - insidemyorgans
Level 26 - ajc064x
Level 27 - Lyropil
Level 28 - llIlO_OllIl
Level 29 - BigBearSaysBoo
Level 30 - 93nu
Level 31 - leandroster
Level 32 - omkrakba3lay
Level 33 - llIlO_OllIl
Level 34 - pannnoobeks
Level 35 - VoidCloser66
Level 36 - Ju1ng
Level 37 - 55_lives
Level 38 - BullfrogBait
Level 39 - TheNafPro
Level 40 - SamWinchesterAnAngel
Level 41 - Noah432
Level 42 - Sertave
Level 43 - Bacconatior
Level 44 - littleace898
Level 45 - coolbuilder08
Level 46 - bringthemtohell
Level 47 - ExploreTheLocal
Level 48 - FrenzoBlox
Level 49 - OverratedRichards101
Level 50 - Doxxorlo
Level 51 - ScriptedDirxct
Level 52 - 1XFINITE
Level 53 - futurepolice1
Level 54 - Yokas_ta04
Level 55 - Atlantic
Level 56 - Gordonrox24
Level 57 - Madpoint83
Level 58 - tiedbyabIoodpact
Level 59 - woozymartin
Level 60 - Alcreon
Level 61 - Puckmonster
Level 62 - lzxi
Level 63 - PRINCESSPETCH
Level 64 - andymewborn
Level 65 - Synth_City
Level 66 - AbstractAlex
Level 67 - EtherealTears
Level 68 - HyperVoxel
Level 69 - WADUMON
Level 70 - LowCircuIation
Level 71 - oaacu
Level 72 - siIcnce
Level 73 - NotSDi
Level 74 - TheSmartRat
Level 75 - D_iz
Level 76 - happyeggplant
Level 77 - KuroStick
Level 78 - Pf2
Level 79 - auhpeach
Level 80 - lifacy
Level 81 - lilb9
Level 82 - enughz
Level 83 - MurderXerif
Level 84 - Avedox
Level 85 - mrdergirlz
Level 86 - Parky43536
Level 87 - JUANSE
Level 88 - DeadBullets
Level 89 - 6xany
Level 90 - Rontoura
Level 91 - AzireBlox
Level 92 - gpr
Level 93 - Simoon68
Level 94 - iiSquare
Level 95 - Stickmasterluke
Level 96 - kni0002
Level 97 - InceptionTime
Level 98 - Webspace
Level 99 - gpr3
Level 100 - Linkmon99

I am assuming that you mentioning not using a bunch of “if” statements is because you had something like this in mind:

if level == 1 then
    -- Code here.

elseif level == 2 then
    -- Code here.

elseif level == 3 then
    -- Code here.
end

So, to avoid all of those “if” statements, you can make a dictionary storing the levels and their respective characters. Then search through that dictionary for the character the player should have. Here is an example:

local characters = {
    ["1"] = "Rareusernamee",
    -- Add the other characters here.
}

local level = -- The location of the player's level.

for requiredLevel, characterName in pairs(characters) do
    if level ~= requiredLevel then
        continue
    end

    -- Other code here, since you have your character now.
end

Or you can just make a regular table and add the characters in order (which I think is best):

local characters = {
    "Rareusernamee"
}

for requiredLevel, characterName in ipairs(characters) do
    if level ~= requiredLevel then
        continue
    end

    -- Other code here, since you have your character now.
end
4 Likes

Thanks for helping me. It very useful!!

Yep using a dictionary would be good like @Ovibion said, but before that since you already have it in text you can just do some string split to process it into a dictionary.

local rankString = [[
Level 1 - Rareusernamee
Level 2 - rareusernameee
Level 3 - Guest_202O1
]]

local lineSplitString = (rankString:split("\n"))
print(lineSplitString)

local dictionary = {}
for i, level in ipairs(lineSplitString) do
	local test = level:split("-")
	lineSplitString[i] = test
	dictionary[test[1]] = test[2]
end

print(dictionary)

image

Might want to process it further to remove those blank spaces

2 Likes