Getattribute not working

I’m making a punch system and I would like to ensure that a player can only punch whenever he equips his fists.

Whenever you equip the systems makes the attribute “equipped” to be true.

The problem is that whenever I want to get the newly set attribute and check it to prevent punching unless equipped is equal to true, the code is essentially ignored and you are allowed to punch regardless of the attributes value

Might sound stupid, but could you add a line after setting the attribute where you print it?

print(Character:GetAttribute("Equipped")

GetAttribute returns the current state of the attribute, not a reference to the attribute. You need to call the function each time you intend to read the attribute’s current state

2 Likes

So then the attribute is set, Explorer’s just not displaying it, for some reason. Also I’m seeing you are getting EquippedAttribute once at the top of the script, which will remain un-updated throughout the game, so watch out for that. (will always be false unless you update it on attribute changed)

1 Like

Took an embarrassingly long time to understand but i get it and it works! Thank you

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