So i want to set “Primary” to be the value of CurrentGun attribute which in this case is Ak47. So for example when I want to print “Primary” it will print the value of the attribute CurrentGun
The changes I made to the code is placing square brackets around “Primary” and “Fists”, as well as placing commas instead of semi-colons to separate them.
I feel like you are very used to a different coding language, and this is a common mistake, so don’t worry and be careful!
EDIT: I made a mistake with square brackets around Fists.
yeah for example if i want to print the first value inside of the table (“Primary”) I want it to print whatever the value of the attribute is (the attribute being “CurrentGun”).
So if the value of the attribute is Ak47 and I go to print primary I want it to print Ak47
If I remember correctly, the reason why you are getting Fists when you do inventory[1] is because Primary is a key-value pair, and Fists is a value in the inventory table.
Now, if you wish to stick with inventory[1], here’s an alternative idea:
printing Primary still prints nil tho ;/ . tho is there a better more modular way to do it since in the future i will want to change the the value of CurrentGun to any weapon that i will have and it will change to that, so if i have Ak47 i cant change it to be a new gun can i?
Hello. I’ve reviewed your code and the reason it prints out nil is because you are setting the attribute of “CurrentGun” to “Ak47” instead of getting the CurrentGun.
This is my mistake, and I will guide you on how to do it:
What is even going on here. Has AI invaded the devforum as well? Why did you decide to include a function without even incorporating arguments? Not to mention the function doesn’t return anything at all, nor does SetAttribute.
OP, as mentioned above, SetAttribute does not return anything back. You would have to use GetAttribute to set the initial value, and use GetAttributeChangedSignal to change your framework.inventory.Primary every time.
Secondly, do not mix dictionaries with arrays. It is impractical - if you want to store someone’s inventory as an array, separate it from the dictionary of their currently equipped items.
My apologies for the mistakes that I’ve made, thank you for correcting me.
I did forget to include arguments into the parameters of the function. I did not read the original post correctly, and noticed there was :SetAttribute() when rereading it.