Referencing a variable with dictionary

Hi

I was wondering how I could use a variable in the name of a dictionary. I will give an example.

local name = player.Name

weaponType  = {
    ["Penguin22305"] = Hammer 
}

print(weaponType.name)   <----- here the script thinks that "name" is in the dictionary when I actually
-----want to reference the variable "name". How could I do this?

Thanks

There is no index or key in your table “weaponType” that is named “name”. Instead, if you want to reference a key using a variable, do this:

weaponType[name]

Reference it as weaponType[name]

Thanks for the help! This is working!

Thanks for the help! This is the solution

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