As far as I see, you’re getting a nil value because you probably do not have any compatible/required items in your inventory.
Since the script doesn’t check if you even have the item at all, its throwing a nil value instead - since it cannot execute the client event because x == nil.