I have a key that u can pick up infinity and I want it where u can only have 1 in ur inventory any help
Two things to check:
- The key is in the player’s character, meaning that they are holding the key out. To check this,
FindFirstChildthe key from the character and if it’s nil, there is no key.
- The key is in the player’s backpack, meaning that they are not holding the key out and it is in the backpack. To check this, get the player and check for
player.Backpackand the same
Combine these statements above and use
or operator, because it could be in either. If either is true, allow the script to not give the key to the player by ending the function promptly by using
return within the if statement’s block.
Alternatively, you can try using a cache that remembers which players are holding a key and checking that list. Slightly more tedious, but probably owrkable.